X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSetColumn.pm;h=3705d5053529d2dc13e8cee776438081b788f024;hb=d71502b;hp=abe61894b546c007ea7ec1ef11a67669c53c978c;hpb=fb13a49f17a0e0a49638080a4bd826fb3702aebe;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index abe6189..3705d50 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -5,7 +5,6 @@ use warnings; use base 'DBIx::Class'; use DBIx::Class::Carp; -use DBIx::Class::Exception; # not importing first() as it will clash with our own method use List::Util (); @@ -94,11 +93,11 @@ sub new { # {collapse} would mean a has_many join was injected, which in turn means # we need to group *IF WE CAN* (only if the column in question is unique) - if (!$orig_attrs->{group_by} && keys %{$orig_attrs->{collapse}}) { + if (!$orig_attrs->{group_by} && $orig_attrs->{collapse}) { if ($colmap->{$select} and $rsrc->_identifying_column_set([$colmap->{$select}])) { $new_attrs->{group_by} = [ $select ]; - delete $new_attrs->{distinct}; # it is ignored when group_by is present + delete @{$new_attrs}{qw(distinct _grouped_by_distinct)}; # it is ignored when group_by is present } else { carp ( @@ -118,7 +117,7 @@ sub new { =item Arguments: none -=item Return Value: \[ $sql, @bind ] +=item Return Value: \[ $sql, L<@bind_values|DBIx::Class::ResultSet/DBIC BIND VALUES> ] =back @@ -423,12 +422,19 @@ Creates the resultset that C uses to run its query. sub func_rs { my ($self,$function) = @_; - return $self->{_parent_resultset}->search( - undef, { - select => {$function => $self->{_select}}, - as => [$self->{_as}], - }, - ); + + my $rs = $self->{_parent_resultset}; + my $select = $self->{_select}; + + # wrap a grouped rs + if ($rs->_resolved_attrs->{group_by}) { + $select = $self->{_as}; + $rs = $rs->as_subselect_rs; + } + + $rs->search( undef, { + columns => { $self->{_as} => { $function => $select } } + } ); } =head2 throw_exception @@ -438,7 +444,7 @@ See L for details. =cut sub throw_exception { - my $self=shift; + my $self = shift; if (ref $self && $self->{_parent_resultset}) { $self->{_parent_resultset}->throw_exception(@_);