From 0b1be0a3f6673341cfacf787490a3a208fb882e3 Mon Sep 17 00:00:00 2001 From: zby Date: Thu, 29 Jan 2009 15:47:33 +0000 Subject: [PATCH] columns first --- lib/DBIx/Class/ResultSet/RecursiveUpdate.pm | 40 +++++++++++--------- t/var/dvdzbr.db | Bin 30720 -> 30720 bytes 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index a152dc0..50be123 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -30,39 +30,31 @@ sub recursive_update { } $object ||= $self->new( {} ); + # first update columns and other accessors - so that later related records can be found for my $name ( keys %$updates ){ - if($object->can($name)){ - my $value = $updates->{$name}; + if( $self->is_for_column( $object, $name, $updates->{$name} ) ) { + $object->$name( $updates->{$name} ); + } + } + for my $name ( keys %$updates ){ + if($object->can($name) && !$self->is_for_column( $object, $name, $updates->{$name} ) ){ # updating relations that that should be done before the row is inserted into the database # like belongs_to - if( $object->result_source->has_relationship($name) - and - ref $value - ){ my $info = $object->result_source->relationship_info( $name ); if( $info and not $info->{attrs}{accessor} eq 'multi' and _master_relation_cond( $object, $info->{cond}, $self->_get_pk_for_related( $name ) ) ){ my $related_result = $object->related_resultset( $name ); - my $sub_object = $related_result->recursive_update( $value ); + my $sub_object = $related_result->recursive_update( $updates->{$name} ); $object->set_from_related( $name, $sub_object ); } - } - # columns and other accessors - elsif( $object->result_source->has_column($name) - or - !$object->can( 'set_' . $name ) - ) { - $object->$name($value); - } } - #warn Dumper($object->{_column_data}); use Data::Dumper; } $self->_delete_empty_auto_increment($object); # don't allow insert to recurse to related objects - we do the recursion ourselves - $object->{_rel_in_storage} = 1; +# $object->{_rel_in_storage} = 1; # warn Dumper( $object->{_column_data} ); $object->update_or_insert; @@ -104,6 +96,20 @@ sub recursive_update { return $object; } +sub is_for_column { + my( $self, $object, $name, $value ) = @_; + return + $object->can($name) + && !( + $object->result_source->has_relationship($name) + && ref( $value ) + ) + && ( + $object->result_source->has_column($name) + || !$object->can( 'set_' . $name ) + ) +} + sub is_m2m { my( $self, $relation ) = @_; my $rclass = $self->result_class; diff --git a/t/var/dvdzbr.db b/t/var/dvdzbr.db index 430d2c06dec9fe097971ac95d0aaca565a800eb2..ffd99d843cf9400d2ac21d617e4f275866891db2 100644 GIT binary patch delta 611 zcmY+AyKmD_6vnwX#+9llF>MmZb{;Mzj-56RptAB1Oh|1>TrrXdu}YMOgOkQ85~5jP zr8@8rWMS$+{3kFUCg$!4iBw`kMdCV2E4afsSKs~aPv1F5XXNONyq8zH=9T}>*6ZWV zha~a2KMqA>sIj*&s;n-fH08o;6jvdVJEa(dpScaP0&lc9l(cwicSmiGnyUW%z;*53 zu-b53*YRxEc#LtVX&JK0tQq0L)~k1IV;d82qGd@upeT;lv)yU{xiHNY;}AvoqrKuW z$&2?Sm{pSSF)vV*;8R{BB7DuS)7>5aS3Yu;q70#;Mv_cSW`_0s0LR*b7~FJLj4_W2 z)QayYrr>+=4v`>hZZZgLn@Ngk*f-l0Gw{vqrZKxDDhe6D9M&5hd+0fB`*5&m5qMS_ z@Tl_Q17)6TRuV{bdXwjT{>AU5$(AsEa+gqCgZt$Yk)dBMNNl#nZ&hdEs`EvRH}E?6 z{WFo-ZQJ+WsGIh)oxN9vmK=+Cy4NpBi;E!6i*Xpr_1u0ui jqk{$b;F%-?UpyoBuVJ2qIVO+7lRh`y~910IYNWK%cLU0i54^f4b$m zrafr19M^R`(>3m*0PC7c<{7Gr$C%yRG>tMwU|-9UWZHv&7h%^ZW1&WbVQ zF$U{}*AylAUbsqPkS(q;6DSuG6yvZ_>`;{9TX8dki8HdIkm2(|v(+^Rp3^aR`m;@e zC#61*NnXCKOmj_2B1w-g@|@3K{~Z}U3XkvIAQV$@t6U-(=#^KJthd?goX)~Erh^!+ zq5^(-pJEzX6&5Q4KPs0gs<2m0LANT*ZS~n~T&HWs;X!pJ&RkBEoF3?ggIPvjA~FLM zIH*Q~ekN7v1NSWKbN7!zZy$3$H#iE7uACjUx$#4bQp`c8mLdYYs`YqWJn17=7rBUq r7eKEUNCIkgJ@|3kGCj*?BMfp|ZKI1z@UC7YDfm)1V*diuY>fB|{W#07 -- 2.45.2