[Dbix-class] Complex table joins
Matt S Trout
dbix-class at trout.me.uk
Mon May 21 18:35:23 GMT 2007
On Mon, May 21, 2007 at 11:39:27AM +0100, Richard Jones wrote:
> I've got table joins working OK where base table_1 (me) contains foreign
> keys to 3 other tables (table_2, table_3 & table_4). So the 'base' (me)
> table_1 contains 3 'belongs_to' relationships, and tables_ 2, 3 & 4 each
> contain a 'has_many' relationship with the base table. Then:
>
> my $rs = $c->model('Schema::Foo')->search( $where_href, # WHERE clause
> {
> select => qw( table1.id table2.field table3.something_else etc ),
> join => [ qw/table_2 table_3 table_4/ ],
The join attribute takes relationship names as defined in your classes; you
-may- make some of these the same as the table name but that's none of DBIC's
business.
The -only- place DBIx::Class takes a table name is in the ->table() statement.
If you think of anything anywhere else as a table name, you'll run into
problems because it isn't.
I think you'll find if you see it as
join => [ qw(belongs_to_1, belongs_to_2), { belongs_to_3 => 'has_many_1' } ]
not only will your code work but everything will be much clearer.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director Want a managed development or deployment platform?
Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/
More information about the Dbix-class
mailing list