From: zby Date: Thu, 13 Nov 2008 08:12:38 +0000 (+0000) Subject: hashrefs in m2m X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=7947dd6ee9711102d5fb3fc579316d830d610da1;p=chaz%2Fp5-DBIx-Class-ResultSet-RecursiveUpdate hashrefs in m2m --- diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index 39366e7..2dc40cb 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -55,10 +55,16 @@ sub recursive_update { # many to many case if( $self->is_m2m( $name ) ) { my ( $pk ) = $self->_get_pk_for_related( $name ); - my @values = @{$updates->{$name}}; my @rows; my $result_source = $object->$name->result_source; - @rows = $result_source->resultset->search({ $pk => [ @values ] } ) if @values; + for my $elem ( @{$updates->{$name}} ){ + if( ref $elem ){ + push @rows, $result_source->resultset->find( $elem ); + } + else{ + push @rows, $result_source->resultset->find( { $pk => $elem } ); + } + } my $set_meth = 'set_' . $name; $object->$set_meth( \@rows ); } diff --git a/t/lib/RunTests.pm b/t/lib/RunTests.pm index e38d1f1..f3bfbb1 100644 --- a/t/lib/RunTests.pm +++ b/t/lib/RunTests.pm @@ -18,7 +18,7 @@ sub run_tests{ my $updates = { id => undef, aaaa => undef, - tags => [ '2', '3' ], + tags => [ '2', { id => '3' } ], name => 'Test name', # 'creation_date.year' => 2002, # 'creation_date.month' => 1, diff --git a/t/var/dvdzbr.db b/t/var/dvdzbr.db index 86a5580..1aad3b8 100644 Binary files a/t/var/dvdzbr.db and b/t/var/dvdzbr.db differ