From: Matt S Trout Date: Wed, 26 Jul 2006 16:13:59 +0000 (+0000) Subject: bugfix for pathological prefetch case X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fe7748d807ab07e1e2f8aeb2ff8335132e6c241d;p=dbsrgits%2FDBIx-Class-Historic.git bugfix for pathological prefetch case --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index c71043b..bc6dd2e 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1550,11 +1550,13 @@ sub _resolved_attrs { my $collapse = $attrs->{collapse} || {}; if (my $prefetch = delete $attrs->{prefetch}) { + $prefetch = $self->_merge_attr({}, $prefetch); my @pre_order; + my $seen = $attrs->{seen_join} || {}; foreach my $p (ref $prefetch eq 'ARRAY' ? @$prefetch : ($prefetch)) { # bring joins back to level of current class my @prefetch = $source->resolve_prefetch( - $p, $alias, { %{$attrs->{seen_join}||{}} }, \@pre_order, $collapse + $p, $alias, $seen, \@pre_order, $collapse ); push(@{$attrs->{select}}, map { $_->[0] } @prefetch); push(@{$attrs->{as}}, map { $_->[1] } @prefetch); diff --git a/t/90join_torture.t b/t/90join_torture.t index 889c968..d2fcd97 100644 --- a/t/90join_torture.t +++ b/t/90join_torture.t @@ -7,7 +7,7 @@ use DBICTest; use Data::Dumper; my $schema = DBICTest->init_schema(); -plan tests => 18; +plan tests => 19; my @rs1a_results = $schema->resultset("Artist")->search_related('cds', {title => 'Forkful of bees'}, {order_by => 'title'}); is($rs1a_results[0]->title, 'Forkful of bees', "bare field conditions okay after search related"); @@ -82,4 +82,17 @@ my $merge_rs_2 = $schema->resultset("Artist")->search({ }, { join => 'cds' })->s is(scalar(@{$merge_rs_2->{attrs}->{join}}), 1, 'only one join kept when inherited'); my $merge_rs_2_cd = $merge_rs_2->next; +eval { + + my @rs_with_prefetch = $schema->resultset('TreeLike') + ->search( + {'me.id' => 1}, + { + prefetch => [ 'parent', { 'children' => 'parent' } ], + }); + +}; + +ok(!$@, "pathological prefetch ok"); + 1;