From: Peter Rabbitson Date: Fri, 19 Jun 2009 14:36:54 +0000 (+0000) Subject: Fix the fix X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6a089afdfa16b498a17bb7b8d4ef2a77c71aea54;p=dbsrgits%2FDBIx-Class-Historic.git Fix the fix --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 530d5aa..1df6b59 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1315,7 +1315,7 @@ sub _adjust_select_args_for_limited_prefetch { } - # mangle the from, separating it into an outer and inner part + # mangle the head of the {from} my $self_ident = shift @$from; # this map indicates which aliases need to be joined if we want @@ -1323,13 +1323,10 @@ sub _adjust_select_args_for_limited_prefetch { # (e.g. join => { cds => 'tracks' } - tracks will need cds too ) my %join_map = map { $_->[0]{-alias} => $_->[0]{-join_path} } (@$from); - my (%inner_joins, %outer_joins); + my (%inner_joins); - # decide which parts of the join will remain - # - # resolve the prefetch-needed joins here as well, as the $attr->{prefetch} - # is 1) resolved away 2) unreliable as it may be a result of search_related - # and whatnot + # decide which parts of the join will remain on the inside + # (we do not need the purely-prefetch ones) # # since we do not have introspectable SQLA, we fall back to ugly # scanning of raw SQL for WHERE, and for pieces of ORDER BY @@ -1360,15 +1357,6 @@ sub _adjust_select_args_for_limited_prefetch { $inner_joins{$_} = 1 for @{$join_map{$alias}}; } } - - # any alias found in the select becomes %outer_joins - # the join parents are included in the same manner - for my $sel (@$select) { - if ($sel =~ /^$alias\./) { - $outer_joins{$alias} = 1; - $outer_joins{$_} = 1 for @{$join_map{$alias}}; - } - } } } @@ -1400,17 +1388,14 @@ sub _adjust_select_args_for_limited_prefetch { $sub_attrs ); - # generate the outer $from - my $outer_from = [ { $alias => $subq } ]; - if (keys %outer_joins) { - for my $j (@$from) { - push @$outer_from, $j if $outer_joins{$j->[0]{-alias}}; - } - } + # put it back in $from + unshift @$from, { $alias => $subq }; - # now _select_args() will continue with the modified set of arguments - # where ended up in the subquery, thus {} - return ($outer_from, $select, {}, $attrs); + # This is totally horrific - the $where ends up in both the inner and outer query + # Unfortunately not much can be done until SQLA2 introspection arrives + # + # OTOH it can be seen as a plus: (notes that this query would make a DBA cry ;) + return ($from, $select, $where, $attrs); } sub _resolve_ident_sources {