From: Alexander Hartmaier Date: Mon, 4 Oct 2010 15:41:52 +0000 (+0200) Subject: more relationship validation in _update_relation X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-DBIx-Class-ResultSet-RecursiveUpdate;a=commitdiff_plain;h=b7b1b75e38ba3bb4ba50c76c33610b725167ed41 more relationship validation in _update_relation --- 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 {