]> Dogcows Code - chaz/p5-DBIx-Class-ResultSet-RecursiveUpdate/commitdiff
more relationship validation in _update_relation
authorAlexander Hartmaier <alexander.hartmaier@t-systems.at>
Mon, 4 Oct 2010 15:41:52 +0000 (17:41 +0200)
committerAlexander Hartmaier <alexander.hartmaier@t-systems.at>
Mon, 4 Oct 2010 15:41:52 +0000 (17:41 +0200)
lib/DBIx/Class/ResultSet/RecursiveUpdate.pm

index da7e9386647f40c8045f05a4ce35521793a52fcd..dcf370752d16a4fa47ac39fbf3c9d11524eff0ec 100644 (file)
@@ -129,7 +129,8 @@ sub recursive_update {
 
         # unknown
         $self->throw_exception(
-            "No such column, relationship, many-to-many helper accessor or generic accessor '$name'");
+            "No such column, relationship, many-to-many helper accessor or generic accessor '$name'"
+        );
     }
 
     # warn 'other: ' . Dumper( \%other_methods ); use Data::Dumper;
@@ -237,10 +238,21 @@ sub _update_relation {
             && $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION
             == $resolved;
 
-    # an arrayref is only valid for has_many rels
-    if ( ref $updates eq 'ARRAY' ) {
+    my $rel_col_cnt = scalar keys %{ $info->{cond} };
+    use Data::Dumper;
+    warn "RELINFO for $name: " . Dumper($info);
+    warn "REL_COL_CNT: $rel_col_cnt";
+
+    #warn "REV RELINFO for $name: " . Dumper($revrelinfo);
+
+    # the only valid datatype for a has_many rels is an arrayref
+    if ( $info->{attrs}{accessor} eq 'multi') {
+        $self->throw_exception( "data for has_many relationship '$name' must be an arrayref")
+            unless ref $updates eq 'ARRAY';
+
         my @updated_ids;
         for my $sub_updates ( @{$updates} ) {
+            warn "updating $name";
             my $sub_object = recursive_update(
                 resultset => $related_resultset,
                 updates   => $sub_updates,
@@ -271,7 +283,9 @@ sub _update_relation {
             }
         }
     }
-    else {
+    elsif ($info->{attrs}{accessor} eq 'single'
+        || $info->{attrs}{accessor} eq 'filter' )
+    {
         my $sub_object;
         if ( ref $updates ) {
 
@@ -309,6 +323,9 @@ sub _update_relation {
                 && $info->{attrs}{join_type} eq 'LEFT' )
             );
     }
+    else {
+        $self->throw_exception( "recursive_update doesn't now how to handle relationship '$name' with accessor " . $info->{attrs}{accessor});
+    }
 }
 
 sub is_m2m {
This page took 0.023971 seconds and 4 git commands to generate.