From: John Napiorkowski Date: Mon, 5 Apr 2010 14:41:42 +0000 (-0400) Subject: test case for might_have and another minor bug fix X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-DBIx-Class-ResultSet-RecursiveUpdate;a=commitdiff_plain;h=8cc7f86b76634bbae9ec36aca0cb2669ebe78a18;hp=75f3ba678630b75516689f3229db48f99f876604 test case for might_have and another minor bug fix --- diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index eeec84c..ce89f38 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -107,8 +107,7 @@ sub recursive_update { # 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 ) { @@ -214,7 +213,7 @@ sub _update_relation { } } 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 ) diff --git a/t/96multi_create.t b/t/96multi_create.t index d1e44b3..6ef75d6 100644 --- a/t/96multi_create.t +++ b/t/96multi_create.t @@ -6,7 +6,7 @@ use Test::Exception; use lib qw(t/lib); use DBICTest; -plan tests => 95; +plan tests => 98; my $schema = DBICTest->init_schema(); @@ -738,4 +738,28 @@ eval { }; 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; diff --git a/t/lib/DBICTest/Schema/CD.pm b/t/lib/DBICTest/Schema/CD.pm index fcd7202..fd380a9 100644 --- a/t/lib/DBICTest/Schema/CD.pm +++ b/t/lib/DBICTest/Schema/CD.pm @@ -38,7 +38,7 @@ __PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist', undef, { }); # 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( diff --git a/t/var/dvdzbr.db b/t/var/dvdzbr.db index 2cb45dc..f114670 100644 Binary files a/t/var/dvdzbr.db and b/t/var/dvdzbr.db differ