From: Matt S Trout Date: Tue, 11 Jul 2006 13:51:31 +0000 (+0000) Subject: all present and correct. I think. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9755b3df195932ab24dec8503f5e4f62f43bbe4c;p=dbsrgits%2FDBIx-Class-Historic.git all present and correct. I think. --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index bbb456e..11a21c0 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1419,10 +1419,10 @@ sub related_resultset { "' has no such relationship $rel") unless $rel_obj; - my ($from,$seen) = $self->search(undef, { join => $rel })->_resolve_from; + my ($from,$seen) = $self->_resolve_from($rel); - my $join_count = $self->{attrs}{seen_join}{$rel}; - my $alias = $join_count ? join('_', $rel, $join_count+1) : $rel; + my $join_count = $seen->{$rel}; + my $alias = ($join_count > 1 ? join('_', $rel, $join_count) : $rel); $self->result_source->schema->resultset($rel_obj->{class})->search_rs( undef, { @@ -1440,7 +1440,7 @@ sub related_resultset { } sub _resolve_from { - my ($self) = @_; + my ($self, $extra_join) = @_; my $source = $self->result_source; my $attrs = $self->{attrs}; @@ -1449,11 +1449,12 @@ sub _resolve_from { my $seen = { %{$attrs->{seen_join}||{}} }; - if ($attrs->{join}) { - push(@{$from}, - $source->resolve_join($attrs->{join}, $attrs->{alias}, $seen) - ); - } + my $join = ($attrs->{join} + ? [ $attrs->{join}, $extra_join ] + : $extra_join); + push(@{$from}, + $source->resolve_join($join, $attrs->{alias}, $seen) + ); return ($from,$seen); } diff --git a/t/76joins.t b/t/76joins.t index e828d6d..dff7046 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -314,7 +314,7 @@ is(eval { $tree_like->children->first->children->first->name }, 'quux', $tree_like = eval { $schema->resultset('TreeLike')->search( { 'children.id' => 2, 'children_2.id' => 5 }, { join => [qw/children children/] } - )->search_related('children', { 'children_3.id' => 6 }, { prefetch => 'children' } + )->search_related('children', { 'children_4.id' => 6 }, { prefetch => 'children' } )->first->children->first; }; is(eval { $tree_like->name }, 'fong', 'Tree with multiple has_many joins ok'); @@ -331,7 +331,7 @@ eval { })->search_related('tracks')->first; }; -like( $sql, qr/^SELECT tracks\.trackid/, "collapsed join didn't add _2 to alias" ); +like( $sql, qr/^SELECT tracks_2\.trackid/, "join not collapsed for search_related" ); $schema->storage->debug($orig_debug); $schema->storage->debugobj->callback(undef); diff --git a/t/90join_torture.t b/t/90join_torture.t index fac8535..724b701 100644 --- a/t/90join_torture.t +++ b/t/90join_torture.t @@ -23,7 +23,7 @@ cmp_ok(scalar @cds, '==', 1, "condition based on inherited join okay"); #this is wrong, should accept me.title really my $rs3 = $rs2->search_related('cds'); -cmp_ok($rs3->count, '==', 9, "Nine artists returned"); +cmp_ok(scalar($rs3->all), '==', 27, "All cds for artist returned"); my $rs4 = $schema->resultset("CD")->search({ 'artist.artistid' => '1' }, { join => ['tracks', 'artist'], prefetch => 'artist' }); my @rs4_results = $rs4->all;