Revision history for DBIx::Class
0.06002
+ - fix set_from_related to accept undef
- fix to Dumper-induced hash iteration bug
- fix to copy() with non-composed resultsource
- fix to ->search without args to clone rs but maintain cache
"condition for $rel is of type ".
(ref $cond ? ref $cond : 'plain scalar')
) unless ref $cond eq 'HASH';
- my $f_class = $self->result_source->schema->class($rel_obj->{class});
- $self->throw_exception( "Object $f_obj isn't a ".$f_class )
- unless $f_obj->isa($f_class);
+ if (defined $f_obj) {
+ my $f_class = $self->result_source->schema->class($rel_obj->{class});
+ $self->throw_exception( "Object $f_obj isn't a ".$f_class )
+ unless $f_obj->isa($f_class);
+ }
$self->set_columns(
$self->result_source->resolve_condition(
$rel_obj->{cond}, $f_obj, $rel));
#warn "$self $k $for $v";
$ret{$k} = $for->get_column($v);
#warn %ret;
+ } elsif (!defined $for) { # undef, i.e. "no object"
+ $ret{$k} = undef;
} elsif (ref $as) { # reverse object
$ret{$v} = $as->get_column($k);
+ } elsif (!defined $as) { # undef, i.e. "no reverse object"
+ $ret{$v} = undef;
} else {
$ret{"${as}.${k}"} = "${for}.${v}";
}
use strict;
use warnings;
-plan tests => 25;
+plan tests => 26;
# has_a test
my $cd = $schema->resultset("CD")->find(4);
} );
$track->set_from_related( cd => $cd );
-if ($INC{'DBICTest/HelperRels.pm'}) { # except inflated object
+if ($INC{'DBICTest/HelperRels.pm'}) { # expect inflated object
is($track->disc->cdid, 4, 'set_from_related ok, including alternative accessor' );
} else {
is( $track->cd, 4, 'set_from_related ok' );
}
+$track->set_from_related( cd => undef );
+
+ok( !defined($track->cd), 'set_from_related with undef ok');
+
+
# update_from_related, the same as set_from_related, but it calls update afterwards
$track = $schema->resultset("Track")->create( {
trackid => 2,