"' 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, {
}
sub _resolve_from {
- my ($self) = @_;
+ my ($self, $extra_join) = @_;
my $source = $self->result_source;
my $attrs = $self->{attrs};
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);
}
$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');
})->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);
#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;