X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-DBIx-Class-ResultSet-RecursiveUpdate;a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet%2FRecursiveUpdate.pm;h=2dc40cba4f7ba698cddb0b5befa90d60a1420249;hp=7115aaa7863d0bb6fe58aaf4e2c2aaa54a9fc4eb;hb=7947dd6ee9711102d5fb3fc579316d830d610da1;hpb=5d6f38c3bcdf0d75e477a32109e09b67343bcfb5 diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index 7115aaa..2dc40cb 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -44,6 +44,8 @@ sub recursive_update { #warn Dumper($object->{_column_data}); use Data::Dumper; } $self->_delete_empty_auto_increment($object); + # don't allow insert to recurse to related objects - we do the recursion ourselves + $object->{_rel_in_storage} = 1; $object->update_or_insert; # updating relations that can be done only after the row is inserted into the database @@ -53,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 ); }