[Dbix-class] Q: prefetch has_many relation

Bernhard Graf dbic4 at augensalat.de
Thu Apr 8 16:10:46 GMT 2010


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).
How do I select all CDs of the artists of $artist_rs with one query?

Bernhard Graf



More information about the DBIx-Class mailing list