test case for might_have and another minor bug fix
authorJohn Napiorkowski <johnn@John-Napiorkowski-MacBook-Pro.local>
Mon, 5 Apr 2010 14:41:42 +0000 (10:41 -0400)
committerJohn Napiorkowski <johnn@John-Napiorkowski-MacBook-Pro.local>
Mon, 5 Apr 2010 14:41:42 +0000 (10:41 -0400)
lib/DBIx/Class/ResultSet/RecursiveUpdate.pm
t/96multi_create.t
t/lib/DBICTest/Schema/CD.pm
t/var/dvdzbr.db

index eeec84cdd240e2007b07101c2d3cd784f184ce62..ce89f3863cb7ed45f8a5ccdb4065f71bd18ba92b 100644 (file)
@@ -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 )
index d1e44b396921c48b5ec69049d4c5c6df31ecb15f..6ef75d620a1163e8af037f0fd6322b2f0046236a 100644 (file)
@@ -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;
index fcd72028051a77ff181d98c4b5c2186290b7258b..fd380a9ff85f326826405a8630fc5b978d1c1adf 100644 (file)
@@ -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(
index 2cb45dc9e6993e1b0ab34ed44aead710670acf55..f11467040981f3be7cb1c9ef4d8983da60bca74f 100644 (file)
Binary files a/t/var/dvdzbr.db and b/t/var/dvdzbr.db differ
This page took 0.023383 seconds and 4 git commands to generate.