# don't allow insert to recurse to related objects - we do the recursion ourselves
# $object->{_rel_in_storage} = 1;
- $object->update_or_insert;
-
+ $object->update_or_insert if $object->is_changed;
# updating many_to_many
for my $name ( keys %$updates ) {
}
}
elsif( ! ref $sub_updates ){
- $sub_object = $related_result->find( $sub_updates )
+ $sub_object = $related_result->find( $sub_updates )
unless (!$sub_updates && ($info->{attrs}{join_type} eq 'LEFT'));
}
$object->set_from_related( $name, $sub_object )
use lib qw(t/lib);
use DBICTest;
-plan tests => 95;
+plan tests => 98;
my $schema = DBICTest->init_schema();
};
diag $@ if $@;
+
+## Test for the might_have is allowed empty bug (should check and see if this
+## needs patching upstream to DBIC
+
+use DBIx::Class::ResultSet::RecursiveUpdate;
+
+my $might_have = {
+ artwork => undef,
+ liner_notes => undef,
+ tracks => [{title=>'hello', pos=>'100'}],
+ single_track_row => undef,
+};
+
+ok my $might_have_cd_rs = $schema->resultset('CD'), 'got a good resultset';
+ok my $might_have_cd_row = $might_have_cd_rs->first, 'got cd to test';
+
+DBIx::Class::ResultSet::RecursiveUpdate::Functions::recursive_update(
+ resultset => $might_have_cd_rs,
+ updates => $might_have,
+ object => $might_have_cd_row,
+);
+
+ok $schema->resultset('Track')->recursive_update($might_have), 'handled might_have';
+
1;
});
# in case this is a single-cd it promotes a track from another cd
-__PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track' );
+__PACKAGE__->belongs_to( single_track_row => 'DBICTest::Schema::Track', {'foreign.trackid'=>'self.single_track'} );
__PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track' );
__PACKAGE__->has_many(