added special handling of has_many rels to tables with a single column pk
authorAlexander Hartmaier <alexander.hartmaier@t-systems.at>
Wed, 6 Oct 2010 11:25:41 +0000 (13:25 +0200)
committerAlexander Hartmaier <alexander.hartmaier@t-systems.at>
Wed, 6 Oct 2010 11:25:41 +0000 (13:25 +0200)
lib/DBIx/Class/ResultSet/RecursiveUpdate.pm

index 27395cccdc03b0b32d3fd84214efce570907a9ed..fcc3b0a92d0bf5d2ccfc840edc5de9ad44b615ab 100644 (file)
@@ -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";
This page took 0.021803 seconds and 4 git commands to generate.