From: Peter Rabbitson Date: Tue, 11 Aug 2009 12:16:28 +0000 (+0000) Subject: Sanify group_by handling in complex prefetch rewrites X-Git-Tag: v0.08109~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=efd7c5e5cbce1805ba3f25a4ed31f3a5d9995603;p=dbsrgits%2FDBIx-Class.git Sanify group_by handling in complex prefetch rewrites --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index e24dafe..7fa5aa1 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1266,8 +1266,8 @@ sub _count_subq_rs { # extra selectors do not go in the subquery and there is no point of ordering it delete $sub_attrs->{$_} for qw/collapse select _prefetch_select as order_by/; - # if we prefetch, we group_by primary keys only as this is what we would get out of the rs via ->next/->all - # clobber old group_by regardless + # if we prefetch, we group_by primary keys only as this is what we would get out + # of the rs via ->next/->all. We DO WANT to clobber old group_by regardless if ( keys %{$attrs->{collapse}} ) { $sub_attrs->{group_by} = [ map { "$attrs->{alias}.$_" } ($rsrc->primary_columns) ] } @@ -1509,7 +1509,8 @@ sub _rs_update_delete { if (my $g = $attrs->{group_by}) { my @current_group_by = map { $_ =~ /\./ ? $_ : "$attrs->{alias}.$_" } - (ref $g eq 'ARRAY' ? @$g : $g ); + @$g + ; if ( join ("\x00", sort @current_group_by) @@ -2871,7 +2872,7 @@ sub _resolved_attrs { ); } - if ($attrs->{group_by} and ! ref $attrs->{group_by}) { + if ($attrs->{group_by} and ref $attrs->{group_by} ne 'ARRAY') { $attrs->{group_by} = [ $attrs->{group_by} ]; } diff --git a/t/prefetch/grouped.t b/t/prefetch/grouped.t index 1811069..9d7c4ca 100644 --- a/t/prefetch/grouped.t +++ b/t/prefetch/grouped.t @@ -258,7 +258,7 @@ for ($cd_rs->all) { '( SELECT COUNT( * ) FROM ( - SELECT me.cd + SELECT SUBSTR(me.cd, 1, 1) FROM track me JOIN cd cd ON cd.cdid = me.cd WHERE ( me.cd IN ( ?, ?, ?, ?, ? ) )