[Dbix-class] Re: Best possible way to retrieve data using relationship

Peter Rabbitson rabbit+dbic at rabbit.us
Fri Dec 31 13:43:41 GMT 2010


Wolfgang Kinkeldei wrote:
> Hello <linuxsupport>,
> 
> looks like nobody answered before...
> 
> You will find an answer to your questions if you carefully read the documentation in
> - DBIx::Class::Manual::Joining
> - DBIx::Class::Manual::Cookbook
> 
> To give a short answer, you should never use "join" and "prefetch" in the same query, these options are mutually exclusive.

^^ this is incorrect, which document claims this?

> If you choose to use "join" your result will have as many rows as your SQL statement retrieves. You will need to add extra "select" or "+select" options paired with "as" or "+as" entries to get the column values from your related tables. Please keep in mind that no extra accessors for "as" / "+as" generated columns will be generated. You must fetch these values via "$result->get_column('name_of_the_column')".

This is also more than half-incorrect

> On the other hand, if you use "prefetch", your resultset will only have the number of rows, that are distinct in the main table of your query. Then, you can access all prefetched tables using their accessor methods. In contrast to a joined DBIx-Query this will not trigger additional SQL fired to your database, as the joined tables' data has already been read. Prefetch by convention always reads every column in all tables used in the query.

This otoh is indeed correct.

Please join us in channel #dbix-class on irc.perl.org so we can clear
up the confusion and guide you towards improving the docs (the core
authors do not really see ambiguities in documentation as they just
know which piece does what inside out).


Cheers!



More information about the DBIx-Class mailing list