[Dbix-class] Complex table joins

Richard Jones ra.jones at dpw.clara.co.uk
Mon May 21 13:53:03 GMT 2007


SHAD0WRUNNER at gmx.de wrote:
>> Based on the Cookbook 'Multi-step joins' section I've tried various 
>> variations of:
>>   join => [ qw/table_2 table_3 table_4 table_5/ ],
>>   join => [ qw/table_2 table_3/], { 'table_4' => 'table_5' } ],
>>   join => [ qw/table_2 table_3/], table_1 => { 'table_4' => 'table_5' } ],
>>   etc.
>>     
>
> I think 
>
> join => [{ 'table_4' => 'table_5' }, qw/table_2 table_3/]
>
> should work.
>   
No, it doesn't. I know the arrayref generates valid sql as I can extract 
it from the DBIC::Profiler output and run it manually. It finds the data 
I want. I have also manually constructed 'from' as a complex data 
structure (see below),  but always the same error: 
"DBIx::Class::ResultSet::single(): No such relationship 'speciality' at 
...."

speciality is the alias for table_5, as in:

from => {
  { me => 'requests' },
  [ # various standard left-joins, then: ],
  [
    { 'speciality' => 'specialities', -join-type => 'left' },
    { 'speciality.id' => table_4.speciality_id' }, # 'speciality.id' now 
foreign key in table_4
  ],
}

I'm retrieving the data as:
$c->model('Schema::Foo')->search($search_criteria_href, 
$select_href)->single # it's a single-record search
Then: No such relationship 'speciality', etc
 
So frustrating!

-- 
Richard Jones 




More information about the Dbix-class mailing list