my @otherrels = $othertable->relationships();
my $otherrelationship;
foreach my $otherrel (@otherrels) {
- my $otherrel_info = $othertable->relationship_info($otherrel);
+ # this may be a partial schema with the related source not being
+ # available at all
+ my $back = try { $othertable->related_source($otherrel) } or next;
- my $back = $othertable->related_source($otherrel);
+ # did we get back to ourselves?
next unless $back->source_name eq $self->source_name;
+ my $otherrel_info = $othertable->relationship_info($otherrel);
my @othertestconds;
if (ref $otherrel_info->{cond} eq 'HASH') {
-alias => $as,
-relation_chain_depth => $seen->{-relation_chain_depth} || 0,
},
- $self->_resolve_condition($rel_info->{cond}, $as, $alias) ];
+ $self->_resolve_condition($rel_info->{cond}, $as, $alias, $join) ];
}
}
our $UNRESOLVABLE_CONDITION = \'1 = 0';
sub _resolve_condition {
- my ($self, $cond, $as, $for) = @_;
- if (ref $cond eq 'HASH') {
+ 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');
+ }
+
+ return $cond->({
+ self_alias => ref $for ? $as : $for,
+ foreign_alias => ref $for ? $self->related_source($rel)->resultset->current_source_alias : $as,
+ self_resultsource => $self,
+ foreign_relname => $rel,
+ self_rowobj => ref $for ? $for : undef
+ });
+
+ } elsif (ref $cond eq 'HASH') {
my %ret;
foreach my $k (keys %{$cond}) {
my $v = $cond->{$k};
} elsif (ref $cond eq 'ARRAY') {
return [ map { $self->_resolve_condition($_, $as, $for) } @$cond ];
} else {
- die("Can't handle condition $cond yet :(");
+ $self->throw_exception ("Can't handle condition $cond yet :(");
}
}