my $query = ((@_ > 1) ? {@_} : shift);
my ($cond) = $self->result_source->resolve_condition($rel_obj->{cond}, $rel, $self);
+ foreach my $key (keys %$cond) {
+ unless ($key =~ m/\./) {
+ $cond->{"me.$key"} = delete $cond->{$key};
+ }
+ }
$query = ($query ? { '-and' => [ $cond, $query ] } : $cond);
#use Data::Dumper; warn Dumper($cond);
#warn $rel_obj->{class}." $meth $cond ".join(', ', @{$attrs->{bind}||[]});
}
#use Data::Dumper; warn Dumper(@{$attrs}{qw/select as/});
$attrs->{from} ||= [ { $alias => $source->from } ];
+ $attrs->{seen_join} ||= {};
if (my $join = delete $attrs->{join}) {
foreach my $j (ref $join eq 'ARRAY'
? (@{$join}) : ($join)) {
$seen{$j} = 1;
}
}
- push(@{$attrs->{from}}, $source->resolve_join($join, $attrs->{alias}));
+ push(@{$attrs->{from}}, $source->resolve_join($join, $attrs->{alias}, $attrs->{seen_join}));
}
$attrs->{group_by} ||= $attrs->{select} if delete $attrs->{distinct};
"No such relationship ${rel} in search_related")
unless $rel_obj;
my $rs = $self->search(undef, { join => $rel });
+ my $alias = ($rs->{attrs}{seen_join}{$rel} > 1
+ ? join('_', $rel, $rs->{attrs}{seen_join}{$rel})
+ : $rel);
return $self->result_source->schema->resultset($rel_obj->{class}
)->search( undef,
{ %{$rs->{attrs}},
- alias => $rel,
+ alias => $alias,
select => undef(),
as => undef() }
)->search(@rest);