From d107f6878c2cb01bc4f498657d9b954603aaae2a Mon Sep 17 00:00:00 2001 From: zby Date: Tue, 30 Sep 2008 09:29:02 +0000 Subject: [PATCH] Updated to curren DBIC. --- lib/DBIx/Class/ResultSet/RecursiveUpdate.pm | 20 ++++++++++++++++---- t/var/dvdzbr.db | Bin 26624 -> 26624 bytes 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index 5934bc4..a176f1f 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -12,7 +12,8 @@ sub recursive_update { my( $self, $updates ) = @_; my $object; # this is a workaround for a bug in the svn version 4794 - if ( ref $self->{cond} eq 'ARRAY' and ref $self->{cond}[0] eq 'SCALAR' ){ +# if ( ref $self->{cond} eq 'ARRAY' and ref $self->{cond}[0] eq 'SCALAR' ){ + if ( ref $self->{cond} eq 'SCALAR' ){ $self->{cond} = {}; $object = $self->new( {} ); } @@ -20,8 +21,10 @@ sub recursive_update { $object = $self->find( $updates, { key => 'primary' } ) || $self->new( {} ); } - for my $name ( keys %$updates ){ if($object->can($name)){ + for my $name ( keys %$updates ){ + if($object->can($name)){ my $value = $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) @@ -34,7 +37,6 @@ sub recursive_update { _master_relation_cond( $object, $info->{cond}, _get_pk_for_related( $object, $name ) ) ){ my $related_result = $object->related_resultset( $name ); - $DB::single = 1; my $sub_object = $related_result->recursive_update( $value ); $object->set_from_related( $name, $sub_object ); } @@ -197,12 +199,22 @@ Then: put 'undef' for the key value - this is then removed and a correct INSERT statement is generated. + For a many_to_many (pseudo) relation you can supply a list of primary keys + from the other table - and it will link the record at hand to those and + only those records identified by them. This is convenient for handling web + forms with check boxes (or a SELECT box with multiple choice) that let you + update such (pseudo) relations. + For a description how to set up base classes for ResultSets see load_namespaces in DBIx::Class::Schema. + The support for many to many pseudo relationships should be treated as prototype - + the DBIC author disagrees with the way I did it. + + =head1 INTERFACE -=for author to fill in: +=for uthor to fill in: =head1 METHODS diff --git a/t/var/dvdzbr.db b/t/var/dvdzbr.db index c4649466382298d8f11feb8f0f2c47f0edd4955e..1b86cea40f1c74a2199cb70b0e1907a6a07ea175 100644 GIT binary patch delta 230 zcmZp;z}Rqsae|akj4uNONCGK#1_te_jXGzTIrbX@xm^2AHnIFwVA`)Y`M=6Nrv3Vp z@2eIt?KhYlsOHDC-*ECmwJN6lMw4aLb(r=WPu}1sHaW}Bg=xPDkQup2!<&U^zs=-{ z`cji;>F`aKOqQ8EQAd|)zv<)yI_*sR%_e*5W;5+KpS;62o25~Ezr|!O-_lw`M=6NroB;< z@2eIt?TwxssOHDCH)irewJN5)v6E%hb(r?XP2S)qHaW}Bg=ud*kQup2!<&U^Z~Ekk z`cji;>F`aKOqQ8EQAd|)Z^GmQI_*q*6DND>W;5+gn!Lj|o25~EZ}Ma=-_