From: Will Hawes Date: Fri, 27 Jan 2006 08:56:21 +0000 (+0000) Subject: update docs for prefetch X-Git-Tag: v0.05005~95 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ae1c90a17bc0b62714b668709afa6fafaa459924;p=dbsrgits%2FDBIx-Class.git update docs for prefetch --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index a63b547..4546c1f 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -756,16 +756,40 @@ For example: } ); -If you want to fetch the columns from the related table as well, see -C below. +If you want to fetch columns from related tables as well, see C +below. -=head2 prefetch +=head2 prefetch arrayref/hashref -Contains a list of relationships that should be fetched along with the main +Contains one or more relationships that should be fetched along with the main query (when they are accessed afterwards they will have already been "prefetched"). This is useful for when you know you will need the related -objects, because it saves a query. Currently limited to prefetching -one relationship deep, so unlike C, prefetch must be an arrayref. +objects, because it saves at least one query: + + my $rs = $schema->resultset('Tag')->search( + {}, + { + prefetch => { + cd => 'artist' + } + } + ); + +The initial search results in SQL like the following: + + SELECT tag.*, cd.*, artist.* FROM tag + JOIN cd ON tag.cd = cd.cdid + JOIN artist ON cd.artist = artist.artistid + +L has no need to go back to the database when we access the +C or C relationships, which saves us two SQL statements in this +case. + +Any prefetched relationship will be joined automatically, so there is no need +for a C attribute in the above search. + +C can be used with the following relationship types: C, +C. =head2 from (arrayref)