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=f86fea6a5fa4d4fca186b7a7eea8d05f3e2c1fa0;hp=0997ff3a8bf854ea4412fcfe89487a9ead358fb6;hb=dc1fe833dfe0abb9031811c18d1cff5f3b968489;hpb=4bb09f7fc7ffdb7adf715d4c42b9be6624809f7d diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index 0997ff3..f86fea6 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -45,6 +45,20 @@ sub recursive_update { my %columns_by_accessor = _get_columns_by_accessor( $self ); for my $name ( keys %$updates ) { my $source = $self->result_source; + if( $name eq 'id' +# && scalar @{$source->primary_columns} == 1 + && !$source->has_column( 'id' ) + ){ + my @ids = ( $updates->{id} ); + if( ref $updates->{id} ){ + @ids = @{ $updates->{id} }; + } + my $i = 0; + for my $key ( $source->primary_columns ){ + $columns{ $key } = $ids[ $i++ ]; + } + next; + } if ( $columns_by_accessor{$name} && !( $source->has_relationship($name) && ref( $updates->{$name} ) ) ) @@ -77,10 +91,9 @@ sub recursive_update { $object = $self->find( \%columns, { key => 'primary' } ); } $object ||= $self->new( {} ); - # first update columns and other accessors - so that later related records can be found for my $name ( keys %columns ) { - $object->$name( $updates->{$name} ); + $object->$name( $columns{$name} ); } for my $name ( keys %other_methods) { $object->$name( $updates->{$name} ) if $object->can( $name ); @@ -103,7 +116,17 @@ sub recursive_update { my ($pk) = _get_pk_for_related( $self, $name); my @rows; my $result_source = $object->$name->result_source; - for my $elem ( @{ $updates->{$name} } ) { + my @updates; + if( ! defined $value ){ + next; + } + elsif( ref $value ){ + @updates = @{ $value }; + } + else{ + @updates = ( $value ); + } + for my $elem ( @updates ) { if ( ref $elem ) { push @rows, $result_source->resultset->find($elem); }