X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource.pm;h=834555aa24fd6716e9568c71172acc2e3bc9fee3;hb=eb3bb737db34965596d2875f9b21bb4912a35160;hp=3e7486095342674b2e4ebd4a09a5759b743a75cd;hpb=9aae35666a35bad290f55e574d053a074c1d6757;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 3e74860..834555a 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -1548,31 +1548,21 @@ sub resolve_condition { # 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; - } - } + my $obj_rel = !!ref $for; - if (! defined $rel) { - $self->throw_exception ('Unable to determine relationship name for condition resolution'); - } - - return $cond->(ref $for ? $as : $for, - ref $for ? 'me' : $as, - $self, - $rel, - ref $for ? $for : undef); + return $cond->({ + self_alias => $obj_rel ? $as : $for, + foreign_alias => $obj_rel ? 'me' : $as, + self_resultsource => $self, + foreign_relname => $rel || ($obj_rel ? $as : $for), + self_rowobj => $obj_rel ? $for : undef + }); } elsif (ref $cond eq 'HASH') { my %ret; @@ -1675,6 +1665,7 @@ sub _resolve_prefetch { "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 =~ /([^\.]+)$/); @@ -1688,6 +1679,7 @@ sub _resolve_prefetch { . 'Use at your own risk.' ); } + #my @col = map { (/^self\.(.+)$/ ? ("${as_prefix}.$1") : ()); } # values %{$rel_info->{cond}}; $collapse->{".${as_prefix}${pre}"} = [ $rel_source->_pri_cols ];