# Resolves the passed condition to a concrete query fragment. If given an alias,
# returns a join condition; if given an object, inverts that object to produce
# a related conditional from that object.
-our $UNRESOLVABLE_CONDITION = \'1 = 0';
+our $UNRESOLVABLE_CONDITION = \ '1 = 0';
sub _resolve_condition {
my ($self, $cond, $as, $for, $rel) = @_;
if (ref $cond eq 'CODE') {
- # heuristic for the actual relname
- if (! defined $rel) {
- if (!ref $as) {
- $rel = $as;
- }
- elsif (!ref $for) {
- $rel = $for;
- }
- }
-
- if (! defined $rel) {
- $self->throw_exception ('Unable to determine relationship name for condition resolution');
- }
+ my $obj_rel = !!ref $for;
return $cond->({
- self_alias => ref $for ? $as : $for,
- foreign_alias => ref $for ? $self->related_source($rel)->resultset->current_source_alias : $as,
+ self_alias => $obj_rel ? $as : $for,
+ foreign_alias => $obj_rel ? 'me' : $as,
self_resultsource => $self,
- foreign_relname => $rel,
- self_rowobj => ref $for ? $for : undef
+ foreign_relname => $rel || ($obj_rel ? $as : $for),
+ self_rowobj => $obj_rel ? $for : undef
});
} elsif (ref $cond eq 'HASH') {
"Can't prefetch has_many ${pre} (join cond too complex)")
unless ref($rel_info->{cond}) eq 'HASH';
my $dots = @{[$as_prefix =~ m/\./g]} + 1; # +1 to match the ".${as_prefix}"
+
if (my ($fail) = grep { @{[$_ =~ m/\./g]} == $dots }
keys %{$collapse}) {
my ($last) = ($fail =~ /([^\.]+)$/);
. 'Use at your own risk.'
);
}
+
#my @col = map { (/^self\.(.+)$/ ? ("${as_prefix}.$1") : ()); }
# values %{$rel_info->{cond}};
$collapse->{".${as_prefix}${pre}"} = [ $rel_source->_pri_cols ];