[Dbix-class] Complex table joins
Richard Jones
ra.jones at dpw.clara.co.uk
Tue May 22 19:48:07 GMT 2007
Matt S Trout wrote:
> On Mon, May 21, 2007 at 08:06:48PM +0100, Richard Jones wrote:
>> I also think the problem is that I haven't managed to find a way to
>> define a relationship in Schema::Foo to a table removed by 2 levels:
>
> You don't. You define a rel in bar and do
>
> join => { name_of_foo_to_bar_rel => 'name_of_bar_to_baz_rel' }
>
> then $foo->name_of_foo_to_bar_rel->name_of_bar_to_baz_rel->the_field_I_want
>
Well, it's still not working :-(
Here's what I have:
Schema::Foo
__PACKAGE__->belongs_to( 'bar', 'Schema::Bar', 'bar_id',
{ join_type => 'left' } );
Schema::Bar
__PACKAGE__->has_many( 'foos', 'Schema::Foo', 'bar_id',
{ join_type => 'left' } );
__PACKAGE__->belongs_to( 'baz', 'Schema::Baz', 'baz_id',
{ join_type => 'left' } );
Schema::Baz
__PACKAGE__->has_many( 'bars', 'Schema::Bar', 'baz_id',
{ join_type => 'left' });
>You don't. You define a rel in bar and do
>
>join => { name_of_foo_to_bar_rel => 'name_of_bar_to_baz_rel' }
OK, so:
name_of_foo_to_bar_rel = foos (has_many rel. in Schema::Bar)
name_of_bar_to_baz_rel = bars (has_many rel. in Schema::Baz)
In Controller:Foo:
join => [ { foos => 'bars' }, @other_relationship_names ],
Here's what I get:
Caught exception in MyApp::Controller::Search->db_lookup
"DBIx::Class::ResultSet::pager(): No such relationship foos at ...
Also tried the belongs_to rel. in Schema::Bar:
join => [ { foos => 'baz' }, @other_relationship_names ],
I've checked & re-checked, but obviously missed it. All other
relationships working fine.
--
Richard Jones
More information about the Dbix-class
mailing list