X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBIHacks.pm;h=47189c90077d75fff4c70c8b7e58bcf1dac5a05d;hb=c97338007ede15e7c62095a642b3de382a3508bd;hp=a8eca164e0a5b2e35c2b4c2e66ed0c9035d5bb70;hpb=571df6765aada245c9882a358cd4269541a178b4;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index a8eca16..47189c9 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -77,10 +77,16 @@ sub _adjust_select_args_for_complex_prefetch { delete $outer_attrs->{$_} for qw/where bind rows offset group_by having/; my $inner_attrs = { %$attrs }; - delete $inner_attrs->{$_} for qw/for collapse _prefetch_selector_range select as/; - - # if the user did not request it, there is no point using it inside - delete $inner_attrs->{order_by} if delete $inner_attrs->{_order_is_artificial}; + delete $inner_attrs->{$_} for qw/for collapse _prefetch_selector_range _collapse_order_by select as/; + + # bring over all non-collapse-induced order_by into the inner query (if any) + # the outer one will have to keep them all + delete $inner_attrs->{order_by}; + if (my $ord_cnt = @{$outer_attrs->{order_by}} - @{$outer_attrs->{_collapse_order_by}} ) { + $inner_attrs->{order_by} = [ + @{$outer_attrs->{order_by}}[ 0 .. $ord_cnt - 1] + ]; + } # generate the inner/outer select lists # for inside we consider only stuff *not* brought in by the prefetch