From 4bb09f7fc7ffdb7adf715d4c42b9be6624809f7d Mon Sep 17 00:00:00 2001 From: zby Date: Thu, 7 May 2009 19:15:44 +0000 Subject: [PATCH] Related rows by id --- lib/DBIx/Class/ResultSet/RecursiveUpdate.pm | 36 ++++++++++++-------- t/var/dvdzbr.db | Bin 37888 -> 37888 bytes 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index 8992718..0997ff3 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -30,6 +30,7 @@ sub recursive_update { if ( blessed($updates) && $updates->isa('DBIx::Class::Row') ) { return $updates; } + # warn Dumper( $updates ); use Data::Dumper; # direct column accessors my %columns; @@ -42,7 +43,6 @@ sub recursive_update { my %post_updates; my %other_methods; my %columns_by_accessor = _get_columns_by_accessor( $self ); - for my $name ( keys %$updates ) { my $source = $self->result_source; if ( $columns_by_accessor{$name} @@ -52,10 +52,10 @@ sub recursive_update { $columns{$name} = $updates->{$name}; next; } - if( !( $source->has_relationship($name) && ref( $updates->{$name} ) ) ){ + if( !( $source->has_relationship($name) ) ){ $other_methods{$name} = $updates->{$name}; + next; } - next if !$source->has_relationship($name); my $info = $source->relationship_info($name); if ( _master_relation_cond( @@ -69,7 +69,7 @@ sub recursive_update { $post_updates{$name} = $updates->{$name}; } } - # warn 'columns: ' . Dumper( \%columns ); use Data::Dumper; + # warn 'other: ' . Dumper( \%other_methods ); use Data::Dumper; my @missing = grep { !exists $columns{$_} && !exists $fixed_fields{$_} } $self->result_source->primary_columns; @@ -154,19 +154,25 @@ sub _update_relation { } else { my $sub_updates = $updates->{$name}; - $sub_updates = { %$sub_updates, %$resolved } if $resolved && ref( $sub_updates ) eq 'HASH'; my $sub_object; - if( $info->{attrs}{accessor} eq 'single' && defined $object->$name ){ - $sub_object = recursive_update( - resultset => $related_result, - updates => $sub_updates, - object => $object->$name - ); + if( ref $sub_updates ){ + $sub_updates = { %$sub_updates, %$resolved } if $resolved && ref( $sub_updates ) eq 'HASH'; + # for might_have relationship + if( $info->{attrs}{accessor} eq 'single' && defined $object->$name ){ + $sub_object = recursive_update( + resultset => $related_result, + updates => $sub_updates, + object => $object->$name + ); + } + else{ + $sub_object = + recursive_update( resultset => $related_result, updates => $sub_updates ); + } + } + elsif( ! ref $sub_updates ){ + $sub_object = $related_result->find( $sub_updates ); } - else{ - $sub_object = - recursive_update( resultset => $related_result, updates => $sub_updates ); - } $object->set_from_related( $name, $sub_object ); } } diff --git a/t/var/dvdzbr.db b/t/var/dvdzbr.db index 7eb36bb5e2e1d46db41dc335067c2696c02c0a08..c31073daa62f17ac817e3cb592b941aa0a032fa6 100644 GIT binary patch delta 662 zcmaKo&uddb5XaxnZjxsbDoxb9BofjHwKjQ4n_5#%+gO{ZLF&PVVi0UAtxYjnt%(5< z>{EuKhtlT=;zd14L98b4C`!Ex{t5m8;!O{Np!={nDB>_bmSy)lGoO_WSlNK}kk9d4 z`NR16W@3x)!h*aFVNT{9n30*I-Vy=9K3JN%$pGV|^EY(Y9Ry6!6ZaKB-Rkf}b^|6U z8NCXaqG!=lfPH4O%qOs)ie0Ax)AYFOrV|I8fn1QbRLwVcW3D#4Fx~&Vddhf^p2qf2 zIhF?;l*e;`hv-La6)1RAbK2eEE zP3{W#{p`+2ZT3QSzJ7gKdU*UyVXRbGz#)p%Du9P+r+x|W2;I^z17_*7zQ%FbZW*RW zNgv<{y+~dI9HmGq$-Fd?lK68pQ;O23RFrA0%3d%0Lu^189FJ0>o@GI*)Qf;)a>18? z$7pm=5+A4cW*RUrw++$9(iC99G8?N}hw@q(0@LSG49VcQWH4>h`Tu7p7PcSTz)rM* LoooXuN?_Gr+c3qg delta 474 zcmah^O-K}R9Nqu#KkjbsP_%vQ?3%N)ezoQ7xUT6XsEZy1r9&dlDyT5ytVo))=0-vL zJ4kgYhZlqp*-?nn-8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