[Dbix-class] Q: prefetch has_many relation

Peter Rabbitson rabbit+dbic at rabbit.us
Thu Apr 8 16:15:33 GMT 2010


Bernhard Graf wrote:
> Artist has_many CDs.
> 
> Assuming a method gets an artist result set $artist_rs.
> 
> I want all CDs of the artists of $artist_rs:
> 
>   while ($artist = $artist_rs->next) {
>     $cd_rs = $artist_rs->cds;
>   }
> 
> This does an extra query for each artist.
> 
> Prefetching a has_many relation is not possible (says the manual).

o.O Please point out where does it say that so we can fix it.

> How do I select all CDs of the artists of $artist_rs with one query?

my $new_rs = $artist_rs->search ({}, { prefetch => 'cds' });



More information about the DBIx-Class mailing list