# back, get a resultset for the current row and do a
# search_related there.
my $row_srcname = $source->source_name;
- my %identity = map { ( $_ => $self->get_column($_) ) } $source->primary_columns;
- my $row_rs = $source->schema->resultset($row_srcname)->search(\%identity);
+ my $base_rs = $source->schema->resultset($row_srcname);
+ my $alias = $base_rs->current_source_alias;
+ my %identity = map { ( "${alias}.${_}" => $self->get_column($_) ) } $source->primary_columns;
+ my $row_rs = $base_rs->search(\%identity);
$row_rs->search_related($rel, $query, $attrs);
my $rel_info = $self->result_source->relationship_info($rel);
if (ref $rel_info->{cond} eq 'CODE') {
my ($cond, $ext) = $rel_info->{cond}->({ self_alias => 'me',
- foreign_alias => 'other',
+ foreign_alias => $rel,
self_rowobj => $self
});
$self->throw_exception("unable to set_from_related - no simplified condition available for '${rel}'")
unless $ext;
+
+ # now we need to make sure all non-identity relationship
+ # definitions are overriden.
+ my ($argref) = @_;
+ while ( my($col, $value) = each %$ext ) {
+ $col =~ s/^$rel\.//;
+ my $vref = ref $value;
+ if ($vref eq 'HASH') {
+ if (keys(%$value) && (keys %$value)[0] ne '=' &&
+ !exists $argref->{$col}) {
+ $self->throw_exception("unable to set_from_related via complex '${rel}' condition on column(s): '${col}'")
+ }
+ }
+ }
}
my $obj = $self->search_related($rel)->create(@_);
if (keys(%$value) && (keys %$value)[0] eq '=') {
$new_data{$col} = $value->{'='};
}
- # in a complex condition, set_from_related needs to override
- # the columns that are involved.
- elsif (!exists $data->{$col} &&
- !exists $data->{"$alias.$col"}) {
- $self->throw_exception("unable to set_from_related via complex condition on column(s): '$col'");
- }
}
elsif( !$vref or $vref eq 'SCALAR' or blessed($value) ) {
$new_data{$col} = $value;
is_same_sql_bind($cds_90s_rs->as_query,
'(SELECT cds_90s.cdid, cds_90s.artist, cds_90s.title, cds_90s.year, cds_90s.genreid,'.
'cds_90s.single_track FROM artist me JOIN cd cds_90s ON ( cds_90s.artist = me.artistid'.
- ' AND ( cds_90s.year < ? AND cds_90s.year > ? ) ) WHERE ( artistid = ? ))',
+ ' AND ( cds_90s.year < ? AND cds_90s.year > ? ) ) WHERE ( me.artistid = ? ))',
[
[ 'cds_90s.year' => 2000 ],
[ 'cds_90s.year' => 1989 ],
- [ 'artistid' => 5 ],
+ [ 'me.artistid' => 5 ],
]);
my @cds_90s = $cds_90s_rs->all;