Hello,

Assuming that there are four tables; race, car, engine, company

car has a foreign key to engine
car has a foreign key to company

I am trying to do a multiple step/multiple join using prefetch. What I am
trying to do is have the following SQL join clause generated (where me is
Race):

LEFT JOIN table_car car ON me.car_id = car.car_id
LEFT JOIN table_engine engine ON car.engine_id = engine.engine_id
LEFT JOIN table_company company ON car.company_id = company.company_id

Originally, I tried:

{
   prefetch => [
      'somerelationship', --- represents some other table I want joined in
but not relevant to this example - only here to show multiple join
      {
         'car' => ['engine', 'company']
      }
   ]
}

But this fails with an error: "No such relationship 'engine' on Race at
/home/rick/perl5/lib/perl5/DBIx/Class/Schema.pm line 1061" . I thought it
would look in the class representing 'car', but it doesn't seem to do that.

Next, I tried:

{
  prefetch => [
     'somerelationship',
     {
        'car' => 'engine',
     },
     {
        'car' => 'company',
     },
  ]
}

The sql join clause generated from this is:

LEFT JOIN table_car car ON me.car_id = car.car_id
LEFT JOIN table_engine engine ON car.engine_id = engine.engine_id
LEFT JOIN table_car car_2 ON me.car_id = car_2.car_id
LEFT JOIN table_company company ON car.company_id = company.company_id

This one also generated the error: "No such relationship 'engine' on Race at
/home/rick/perl5/lib/perl5/DBIx/Class/Schema.pm line 1061"

What is the correct syntax for generating the join clause I want?

Rick
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to