X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-DBIx-Class-ResultSet-RecursiveUpdate;a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet%2FRecursiveUpdate.pm;h=f440967e4dc75e99ec5ece4631f5d030fba913a3;hp=1c408252dff1cbaef14d3d587224963634d7ceda;hb=396ed4908c6ebb6c42f7abac90f0cf5ac5610e54;hpb=073ab86177b3de3f95b1d2a0dc97f3e8e582c7a6 diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index 1c40825..f440967 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -1,6 +1,6 @@ package DBIx::Class::ResultSet::RecursiveUpdate; -use version; $VERSION = qv('0.001'); +use version; $VERSION = qv('0.002'); use warnings; use strict; @@ -75,7 +75,7 @@ sub recursive_update { my $info = $object->result_source->relationship_info($name); $self->_update_relation( $name, $updates, $object, $info ); } - $self->_delete_empty_auto_increment($object); +# $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; @@ -132,17 +132,17 @@ sub _update_relation { # warn 'resolved: ' . Dumper( $resolved ); use Data::Dumper; $resolved = undef - if $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION == $resolved; + if defined $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION && $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION == $resolved; if ( ref $updates->{$name} eq 'ARRAY' ) { for my $sub_updates ( @{ $updates->{$name} } ) { - $sub_updates = { %$sub_updates, %$resolved } if $resolved; + $sub_updates = { %$sub_updates, %$resolved } if $resolved && ref( $sub_updates ) eq 'HASH'; my $sub_object = $related_result->recursive_update( $sub_updates ); } } else { my $sub_updates = $updates->{$name}; - $sub_updates = { %$sub_updates, %$resolved } if $resolved; + $sub_updates = { %$sub_updates, %$resolved } if $resolved && ref( $sub_updates ) eq 'HASH'; my $sub_object = $related_result->recursive_update( $sub_updates ); $object->set_from_related( $name, $sub_object ); @@ -270,6 +270,7 @@ Then: =head1 DESCRIPTION +This is the first release - so treat it as experimental. You can feed the ->create method with a recursive datastructure and have the related records created. Unfortunately you cannot do a similar thing with update_or_create - this module @@ -302,12 +303,13 @@ then you need to inform recursive_update about additional predicate with a secon [ 'id' ] ); +This will work with a new DBIC release. 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. +update such (pseudo) relations. For a description how to set up base classes for ResultSets see load_namespaces in DBIx::Class::Schema.