From: Alexander Hartmaier Date: Wed, 6 Oct 2010 11:25:41 +0000 (+0200) Subject: added special handling of has_many rels to tables with a single column pk X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=b09b840cdf99eb0279eba29f46b2a98fd67b8c82;p=chaz%2Fp5-DBIx-Class-ResultSet-RecursiveUpdate added special handling of has_many rels to tables with a single column pk --- diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index 27395cc..fcc3b0a 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -303,20 +303,31 @@ sub _update_relation { my @cond; my @related_pks = $related_resultset->result_source->primary_columns; - for my $obj (@updated_objs) { - my %cond_for_obj; - for my $col (@related_pks) { - $cond_for_obj{$col} = $obj->get_column($col); + + my $rs_rel_delist = $object->$name; + + # foreign table has a single pk column + if ( scalar @related_pks == 1 ) { + $rs_rel_delist = $rs_rel_delist->search_rs( + { $related_pks[0] => + { -not_in => [ map ( $_->id, @updated_objs ) ] } + } + ); + } + # foreign table has multiple pk columns + else { + for my $obj (@updated_objs) { + my %cond_for_obj; + for my $col (@related_pks) { + $cond_for_obj{$col} = $obj->get_column($col); + } + push @cond, \%cond_for_obj; } - push @cond, \%cond_for_obj; + $rs_rel_delist = $rs_rel_delist->search_rs({ -not => [@cond] }); } - my %cond = ( -not => [@cond] ); #warn "\tCOND: " . Dumper(\%cond); - my $rs_rel_delist = $object->$name->search_rs( \%cond ); - #my $rel_delist_cnt = $rs_rel_delist->count; - my @foo = $rs_rel_delist->all; if ( $if_not_submitted eq 'delete' ) { #warn "\tdeleting related rows: $rel_delist_cnt\n";