Skip Menu |

This queue is for tickets about the DBIx-Class-ResultSet-RecursiveUpdate CPAN distribution.

Report information
The Basics
Id: 77264
Status: resolved
Priority: 0/
Queue: DBIx-Class-ResultSet-RecursiveUpdate

People
Owner: Nobody in particular
Requestors: LUKAST [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.25
Fixed in: (no value)



Subject: recursive update dies when updating multi-pk has_many relations
Recursive update dies when has_many relationships with more than one primary key are updated, if one of the primary keys is named "id". The reason is that recursive update calls 'find($updates->{id}, ...)' without further checks if "id" is present in the updates hash, which does not correspond to find's api if the table has more than one pk. See the attached test and patch. I think someone with deeper knowledge about RU will find a more elegant solution than the one included in my patch, but the patch solves the problem and does not break any of the included tests, so I guess it is ok.
Subject: multi-pk_hasmany.patch
--- /home/lukast/perl5/perlbrew/perls/perl-5.14.2_threads/lib/site_perl/5.14.2/DBIx/Class/ResultSet/RecursiveUpdate.pm 2012-04-13 04:18:54.000000000 +0200 +++ lib/DBIx/Class/ResultSet/RecursiveUpdate.pm 2012-05-17 17:14:55.000000000 +0200 @@ -42,7 +42,7 @@ } use Carp::Clan qw/^DBIx::Class|^HTML::FormHandler|^Try::Tiny/; use Scalar::Util qw( blessed ); -use List::MoreUtils qw/ any /; +use List::MoreUtils qw/ any all/; use Try::Tiny; sub recursive_update { @@ -75,7 +75,12 @@ return $updates; } - if ( !defined $object && exists $updates->{id} ) { + if ( !defined $object && all { exists $updates->{$_} } $self->result_source->primary_columns ) { + + my @pks = map {$updates->{$_} } $self->result_source->primary_columns; + $object = $self->find( @pks, { key => 'primary' } ); + } + elsif ( !defined $object && exists $updates->{id} ) { # warn "finding object by id " . $updates->{id} . "\n"; $object = $self->find( $updates->{id}, { key => 'primary' } );
Subject: multi_pk_hasmany-tests.tar.bz2
Download multi_pk_hasmany-tests.tar.bz2
application/x-bzip 1.2k

Message body not shown because it is not plain text.

Thanks, Lukas.