use warnings;
package DBIx::Class::ResultSet::RecursiveUpdate;
-use version; our $VERSION = qv('0.005');
+use version; our $VERSION = qv('0.007');
use base qw(DBIx::Class::ResultSet);
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} ) )
)
$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 );
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);
}
=head1 VERSION
-This document describes DBIx::Class::ResultSet::RecursiveUpdate version 0.004
+This document describes DBIx::Class::ResultSet::RecursiveUpdate version 0.006
=head1 SYNOPSIS
The functional interface:
my $new_item = DBIx::Class::ResultSet::RecursiveUpdate::Functions::recursive_update({
- id => 1,
- owned_dvds => [
- {
- title => 'One Flew Over the Cuckoo's Nest'
- }
- ]
- }
- );
+ resultset => $schema->resultset( 'Dvd' ),
+ updates => {
+ id => 1,
+ owned_dvds => [
+ {
+ title => 'One Flew Over the Cuckoo's Nest'
+ }
+ ]
+ }
+ });
As ResultSet subclass: