-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');
+ }
+
+ $cond = $cond->(
+ $for,
+ ref $for ? 'me' : $as,
+ $self,
+ $rel,
+ );
+
+ } 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 :(");
}
}
for (keys %$cond) {
my $v = $cond->{$_};
if (ref $v) {
- croak (ref($v) . qq{ reference arguments are not supported in JOINS - try using \"..." instead'})
- if ref($v) ne 'SCALAR';
+ #croak (ref($v) . qq{ reference arguments are not supported in JOINS - try using \"..." instead'})
+ # if ref($v) ne 'SCALAR';
$j{$_} = $v;
}
else {
__PACKAGE__->has_many(
cds_80s => 'DBICTest::Schema::CD',
sub {
- my ( $self_alias, $rel_alias, $self_rsrc, $rel_name ) = @_;
- return {
- "${rel_alias}.artist" => \ "${self_alias}.artistid",
- "${rel_alias}.year" => { '>', "1979" },
- "${rel_alias}.year" => { '<', "1990" }
- };
+ my ( $me, $as, $self_rsrc, $rel ) = @_;
+ return {
+ "${as}.artist" => (ref $me ? $me->artistid : { '=' => \"${me}.artistid"}),
+ "${as}.year" => { '>', "1979",
+ '<', "1990" }
+ };
}
);
'next_track',
__PACKAGE__,
sub {
- my ( $self_alias, $rel_alias, $self_rsrc, $rel_name ) = @_;
+ my ( $me, $as, $self_rsrc, $rel_name ) = @_;
return {
- "${self_alias}.cd" => \ "${rel_alias}.cd",
- "${self_alias}.position" => { '<', \ "${rel_alias}.position" },
+ "${as}.cd" => (ref $me ? $me->cd : { '=' => \"${me}.cd" }),
+ "${as}.position" => { '>', (ref $me ? $me->position : \"${me}.position" )},
};
},
);
my $artist = $schema->resultset("Artist")->create({ name => 'Michael Jackson' });
+
foreach my $year (1975..1985) {
$artist->create_related('cds', { year => $year, title => 'Compilation from ' . $year });
}
is_deeply (
[$last_tracks->get_column ('trackid')->all],
- \@last_track_ids,
+ [ grep { $_ } @last_track_ids ],
'last group-entry via self-join works',
);