[Dbix-class] Is it possible to do a multiple join to same table prefetch?

Rick Apichairuk rick.apichairuk at gmail.com
Tue Dec 28 21:58:39 GMT 2010


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 =3D car.car_id
LEFT JOIN table_engine engine ON car.engine_id =3D engine.engine_id
LEFT JOIN table_company company ON car.company_id =3D company.company_id

Originally, I tried:

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

The sql join clause generated from this is:

LEFT JOIN table_car car ON me.car_id =3D car.car_id
LEFT JOIN table_engine engine ON car.engine_id =3D engine.engine_id
LEFT JOIN table_car car_2 ON me.car_id =3D car_2.car_id
LEFT JOIN table_company company ON car.company_id =3D 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20101228/83f=
37bcd/attachment.htm


More information about the DBIx-Class mailing list