From b09b840cdf99eb0279eba29f46b2a98fd67b8c82 Mon Sep 17 00:00:00 2001 From: Alexander Hartmaier Date: Wed, 6 Oct 2010 13:25:41 +0200 Subject: [PATCH] added special handling of has_many rels to tables with a single column pk --- lib/DBIx/Class/ResultSet/RecursiveUpdate.pm | 29 ++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) 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"; -- 2.43.0