From: Will Hawes Date: Fri, 20 Jan 2006 10:19:45 +0000 (+0000) Subject: note that group_by takes listref rather than list + provide example X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=675ce4a644680c26e0dabdd27450b25baa2b0e36;p=dbsrgits%2FDBIx-Class-Historic.git note that group_by takes listref rather than list + provide example --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index ae6fb3e..38efc79 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -40,6 +40,20 @@ sub new { #use Data::Dumper; warn Dumper($attrs); $attrs = Storable::dclone($attrs || {}); # { %{ $attrs || {} } }; my %seen; + + # wrong! we cannot delete select/as because it will interfere with the count() method. need to just set alias correctly in the first instance +=pod + if( $attrs->{from} && $attrs->{alias} eq 'me' ) { + my @keys = keys( %{$attrs->{from}->[0]} ); + $attrs->{alias} = $keys[0]; + delete $attrs->{select}; + delete $attrs->{as}; + #die Dumper $attrs; + } +=cut +# alias should be set in accordance with from if alias is not defined or = "me" +# could also alter the line below instead, i.e. use alias if defined, then get from "from", then class->table, then "me" as a last resort. + my $alias = ($attrs->{alias} ||= 'me'); if (!$attrs->{select}) { my @cols = ($attrs->{cols} @@ -541,11 +555,13 @@ for an unpaged resultset. For a paged resultset, how many rows per page -=head2 group_by +=head2 group_by (listref) -A list of columns to group by (note that 'count' doesn't work on grouped +A listref of columns to group by (note that 'count' doesn't work on grouped resultsets) + group_by => [qw/ column1 column2 ... /] + =head2 distinct Set to 1 to group by all columns