-sub recursive_update {
- my( $self, $updates ) = @_;
- my $object;
- $object = $self->find( $updates, { key => 'primary' } ) || $self->new( {} );
-
- 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)
- 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}, _get_pk_for_related( $object, $name ) )
- ){
- my $related_result = $object->related_resultset( $name );
- my $sub_object = $related_result->recursive_update( $value );
- $object->set_from_related( $name, $sub_object );
- }
+sub recursive_update {
+ my ( $self, $updates, $fixed_fields ) = @_;
+ return DBIx::Class::ResultSet::RecursiveUpdate::Functions::recursive_update(
+ resultset => $self,
+ updates => $updates,
+ fixed_fields => $fixed_fields
+ );
+}
+
+package DBIx::Class::ResultSet::RecursiveUpdate::Functions;
+use Carp;
+use Scalar::Util qw( blessed );
+
+
+sub recursive_update {
+ my %params = @_;
+ my ( $self, $updates, $fixed_fields, $object ) = @params{ qw/resultset updates fixed_fields object/ };
+ # warn 'entering: ' . $self->result_source->from();
+ carp 'fixed fields needs to be an array ref' if $fixed_fields && ref($fixed_fields) ne 'ARRAY';
+ my %fixed_fields;
+ %fixed_fields = map { $_ => 1 } @$fixed_fields if $fixed_fields;
+ if ( blessed($updates) && $updates->isa('DBIx::Class::Row') ) {
+ return $updates;
+ }
+ # warn Dumper( $updates ); use Data::Dumper;
+ # direct column accessors
+ my %columns;
+
+ # relations that that should be done before the row is inserted into the database
+ # like belongs_to
+ my %pre_updates;
+
+ # relations that that should be done after the row is inserted into the database
+ # like has_many and might_have
+ 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( $name eq 'id'
+# && scalar @{$source->primary_columns} == 1
+ && !$source->has_column( 'id' )
+ ){
+ my @ids = ( $updates->{id} );
+ if( ref $updates->{id} ){
+ @ids = @{ $updates->{id} };