X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FCookbook.pod;h=c22e947c4f0f3ef129a1d717e804b459235eff58;hb=897342e412d5803d73f34ef23b3bdead1835325e;hp=ec8948efa25f5cfa3eb2e0d70d17a21e555ae2fd;hpb=ae1c90a17bc0b62714b668709afa6fafaa459924;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index ec8948e..c22e947 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -231,8 +231,7 @@ main query. Five CDs, five extra queries. A hundred CDs, one hundred extra queries! Thankfully, L has a C attribute to solve this problem. -This allows you to fetch results from a related table as well as the main table -for your class: +This allows you to fetch results from related tables in advance: my $rs = $schema->resultset('CD')->search( { @@ -325,6 +324,31 @@ notes: # WHERE liner_notes.notes LIKE '%some text%' # AND author.name = 'A. Writer' +=head2 Multi-step prefetch + +From 0.04999_05 onwards, C can be nested more than one relationship +deep using the same syntax as a multi-step join: + + my $rs = $schema->resultset('Tag')->search( + {}, + { + prefetch => { + cd => 'artist' + } + } + ); + + # Equivalent SQL: + # SELECT tag.*, cd.*, artist.* FROM tag + # JOIN cd ON tag.cd = cd.cdid + # JOIN artist ON cd.artist = artist.artistid + +Now accessing our C and C relationships does not need additional +SQL statements: + + my $tag = $rs->first; + print $tag->cd->artist->name; + =head2 Transactions As of version 0.04001, there is improved transaction support in