[Dbix-class] Weird RelationShip => SQL behavior and Performance Issue

Jess Robinson castaway at desert-island.me.uk
Thu May 31 09:39:37 GMT 2007


On Thu, 31 May 2007, Benoit Plessis wrote:

>
> hi everyone,

Hiho

> I'm knew to DBIx::Class (discovered with the Catalyst framework) but
> i think it's terrible !

Errm, did that mean good?

> Anyway i encountered two gotchas while using the thing and here they are:
>
> 1/ Relationships.
>
> Let's say we have 3 tables and two relation:
>    table1.rel1 is a *might_have* on table2
>    table2.rel2 is a *belongs_to* on table3

Would you paste the actual fields, FKs etc, so we can make sure you got 
"belongs_to" and "might_have" right ?

> when doing someting like that:
>   $schema->resultset('Table1') -> search (undef, { prefetch => { 'table2' => 
> 'table3' } });
> the generated SQL code will be something like that:
>
>   /FROM table1 LEFT JOIN table2 ON (table1.f1 = table2.f1) JOIN table3 ON 
> (table2.f2 = table3.f2)

Yes, you can change the default type of JOIN by using "join_type" in the 
relationship attributes (see docs).


No idea about the performance stuff, tho the more complex your prefetch 
queries, the more work DBIC will have to do to untangle the results back 
in to objects..

Jess




More information about the Dbix-class mailing list