From: Matt S Trout Date: Mon, 16 Apr 2012 20:40:50 +0000 (+0000) Subject: handle select aliases correctly in group by generation for distinct X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e99f55c000ac8466daa53b254239feb0e28c0ed5;p=dbsrgits%2FDBIx-Class-Historic.git handle select aliases correctly in group by generation for distinct --- diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index 656c659..cab4fc4 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -393,8 +393,12 @@ sub _group_over_selection { } my $select_list = $conv->_select_field_list_to_dq($select); my (@group_by, %group_seen); + my %select_aliases; foreach my $entry (@$select_list) { - $entry = $entry->{alias} if $entry->{type} eq DQ_ALIAS; + if ($entry->{type} eq DQ_ALIAS) { + $select_aliases{$entry->{to}} = 1; + $entry = $entry->{from} + } if ($entry->{type} eq DQ_IDENTIFIER) { push @group_by, \$entry; $group_seen{join('.',@{$entry->{elements}})} = 1; @@ -413,9 +417,11 @@ sub _group_over_selection { while ($order_dq) { if ($order_dq->{by}{type} eq DQ_IDENTIFIER) { my @el = @{$order_dq->{by}{elements}}; - unshift @el, $col_map{$el[0]} if @el == 1 and $col_map{$el[0]}; - push @group_by, \$order_dq->{by} - unless $group_seen{join('.',@el)}; + unless(@el == 1 and $select_aliases{$el[0]}) { + unshift @el, $col_map{$el[0]} if @el == 1 and $col_map{$el[0]}; + push @group_by, \$order_dq->{by} + unless $group_seen{join('.',@el)}; + } } $order_dq = $order_dq->{from}; }