From: Will Hawes Date: Fri, 20 Jan 2006 15:00:42 +0000 (+0000) Subject: added GROUP BY example X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6607ee1b42ae26851e8bd633f6d4f1edbd3b8b4c;p=dbsrgits%2FDBIx-Class-Historic.git added GROUP BY example --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 40da3c7..9bdce36 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -159,6 +159,25 @@ any of your aliases using either of these: } ); +=head2 Grouping results + +DBIx::Class supports GROUP BY as follows: + + $rs = $schema->resultset('Artist')->search( + {}, + { + join => [qw/ cds /], + select => [ 'name', { count => 'cds.cdid' } ], + as => [qw/ name cd_count /], + group_by => [qw/ name /] + } + ); + + # e.g. + # SELECT name, COUNT( cds.cdid ) FROM artist me + # LEFT JOIN cd cds ON ( cds.artist = me.artistid ) + # GROUP BY name + =head2 Using joins and prefetch You can use the "join" attribute to allow searching on, or sorting your