From 8cc7f86b76634bbae9ec36aca0cb2669ebe78a18 Mon Sep 17 00:00:00 2001 From: John Napiorkowski Date: Mon, 5 Apr 2010 10:41:42 -0400 Subject: [PATCH] test case for might_have and another minor bug fix --- lib/DBIx/Class/ResultSet/RecursiveUpdate.pm | 5 ++-- t/96multi_create.t | 26 +++++++++++++++++++- t/lib/DBICTest/Schema/CD.pm | 2 +- t/var/dvdzbr.db | Bin 36864 -> 37888 bytes 4 files changed, 28 insertions(+), 5 deletions(-) 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 2cb45dc9e6993e1b0ab34ed44aead710670acf55..f11467040981f3be7cb1c9ef4d8983da60bca74f 100644 GIT binary patch delta 743 zcmZ`$O-xfk5Z;}Ayq1<~U-@~IHZ4Cjkw7cLSrZ`~Of{ia4YAP(X+iQ7F9!O`j|>O@ zHP+#xiP7MNiy=@opa(s1F+`&$i4o5p8V@EKV~o>6;zeh6W;fr?emg%i4`F5jZa4Vk zwAhkb-Xz^j~-<*Y#_TZ`q)>Yi+v@+vgWRldcklO z6}`Q#6@CYFtzH)!LTtz$xd=gct>#(hN}505H%@j1!#~ zK%#YFVDM~aY$U@m!($8|ritu97@nfLs-NC8dgU~IZnWe@dIgq-Z7Aq@(_=tM`{a9- zLdb8XmLr<8*(ojyUSB23CGf!$_@TzsB~?%bCS|co3bTBk4W+~Jc+RYIf z4@5WrP8@Y~Im~caVyav>db-O$gj5^)>6YE$KvOs47~mcq0&JkQY+U0<)s)U%0jy!( gYbuJhWKZyb>S$r2pJ#5;OFN}(tfy)_2W6tRKjbyg%>V!Z delta 478 zcmY*VPe{{o6n}rd`BUd~`?;;$e#hcZa3Lpl#Cq(%e<#oSil4~ilr z{Qlmho1-FvC}@jjh;`{+K^H;2c9?rr0Wu(H|$&
PttQs z*do<*2K`b`-^Erb9M=_FZE@x23EOe}#*2jxpo8b}6A|& z$^1Cl@+lvtzBc(f*N*`+>X3Loga61Hw##y17DLiq9Kf*56i3RJuqTEepc!&NQJSP5 z#{Uak#UL)gXUJ(ctA;uo4vS8lQA0-$nvf*)Ny