From: Zbigniew Lukasiak Date: Wed, 19 Aug 2009 17:15:41 +0000 (+0200) Subject: updating related many to many X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=ce9a63106394833955cf6fdcfadce46495903458;p=chaz%2Fp5-DBIx-Class-ResultSet-RecursiveUpdate updating related many to many --- 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 0a0d88f..d2eb07c 100644 Binary files a/t/var/dvdzbr.db and b/t/var/dvdzbr.db differ