From b7b1b75e38ba3bb4ba50c76c33610b725167ed41 Mon Sep 17 00:00:00 2001 From: Alexander Hartmaier Date: Mon, 4 Oct 2010 17:41:52 +0200 Subject: [PATCH] more relationship validation in _update_relation --- lib/DBIx/Class/ResultSet/RecursiveUpdate.pm | 25 +++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index da7e938..dcf3707 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -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 { -- 2.45.2