From ce9a63106394833955cf6fdcfadce46495903458 Mon Sep 17 00:00:00 2001 From: Zbigniew Lukasiak Date: Wed, 19 Aug 2009 19:15:41 +0200 Subject: [PATCH] updating related many to many --- lib/DBIx/Class/ResultSet/RecursiveUpdate.pm | 2 +- t/lib/RunTests.pm | 19 +++++++++++++++++-- t/var/dvdzbr.db | Bin 37888 -> 37888 bytes 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index cf70e39..df5d76d 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -131,7 +131,7 @@ sub recursive_update { } for my $elem ( @updates ) { if ( ref $elem ) { - push @rows, $result_source->resultset->find($elem); + push @rows, recursive_update( resultset => $result_source->resultset, updates => $elem ); } else { push @rows, diff --git a/t/lib/RunTests.pm b/t/lib/RunTests.pm index f391fc6..fea0b46 100644 --- a/t/lib/RunTests.pm +++ b/t/lib/RunTests.pm @@ -9,7 +9,7 @@ use DBIx::Class::ResultSet::RecursiveUpdate; sub run_tests{ my $schema = shift; - plan tests => 36; + plan tests => 40; my $dvd_rs = $schema->resultset( 'Dvd' ); my $user_rs = $schema->resultset( 'User' ); @@ -117,7 +117,7 @@ sub run_tests{ ok ( $schema->resultset( 'Twokeys' )->find( { dvd_name => 'New Test Name', key2 => 1 } ), 'Twokeys updated' ); ok ( !$schema->resultset( 'Twokeys' )->find( { dvd_name => $dvd->name, key2 => 1 } ), 'Twokeys updated' ); - # repeatable +# repeatable $updates = { name => 'temp name', @@ -198,6 +198,21 @@ sub run_tests{ ); is( $user->borrowed_dvds->count, 1, 'if_not_submitted delete' ); + my @tags = $schema->resultset( 'Tag' )->search(); + $dvd_updated = DBIx::Class::ResultSet::RecursiveUpdate::Functions::recursive_update( + resultset => $schema->resultset( 'Dvd' ), + updates => { + id => $dvd->dvd_id, # id instead of dvd_id + tags => [ { id => $tags[0]->id, file => 'file0'}, { id => $tags[1]->id, file => 'file1' } ], + } + ); + $tags[$_]->discard_changes for 0 .. 1; + is( $tags[0]->file, 'file0', 'file set in tag' ); + is( $tags[1]->file, 'file1', 'file set in tag' ); + my @rel_tags = $dvd_updated->tags; + is( scalar @rel_tags, 2, 'tags related' ); + ok( $rel_tags[0]->file eq 'file0' || $rel_tags[0]->file eq 'file1', 'tags related' ); + # $updates = { # name => 'Test name 1', diff --git a/t/var/dvdzbr.db b/t/var/dvdzbr.db index 0a0d88f3ad67dce87881847e47847fbcfa6667dc..d2eb07c4c162e7e10932566725bb313c8772fd31 100644 GIT binary patch delta 995 zcmZ{iO-xfk5Xax{JYL&pYeCQ!i}aNu2&n;#M)8Xv3I_2jV*Dtgg;qrhDs7b_DAj`p z4M^ukGF6NR5)Wvbcrh^=4|*}in0QhT>cK?8;DM+Y-ABO$jGOFEcK4r|`OQrKDDNNT zHL9tEGjU@c!o(gEV*I|RIVCi{lZL1&rdL@8Tyy$cDbxt1T2Gb3C2_E z>W{E2i$O8l6*#Xo20~$Nm#-th)M?3A3BIP(bsr!*TP|kvB&pvUm>h3(U|}c^ZyBG! zVLFD_;$9>96kCOph4Acp8)je?rxvVe3dWnAoLbS_@jF7$`^txxh%d&DBR@>w)r|m z)`nb*-^z8JzsuL*3+uXyG|q$s6Df7iCn(MO5AZJueo6XRWs1E(Y!zK0Cu;I_eA>81 z5LTxNx6CK3`AfKUhH%?IgtfDTbz;h1D0)8>C3)~iwvo>?CmFPxWheo}yzb?en1v1) zYz_yD?WJ}cv+kB-%Jc+zIGw{+MN8R2)OvE_#YZ`vM_;i=wl-5Y4n~XEVtf#-0_#-x`|UCZmzrvX>a8-darSwqbi)i`vX60 BB%J^N delta 1015 zcmb7DUuct86u}j10WDirz=EGoCa15F5!QG_#;+}TloVSbWJ)(gQ7J3PkW!)Af}(4-Ntk2|>zxUV zbywomg{FOK{GV*bUgx z7{}3V5u9iY2nyouMp+|-%}q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