+ #warn "\tupdating has_many rel '$name' ($rel_col_cnt columns cols)\n";
+ for my $sub_updates ( @{$updates} ) {
+ my $sub_object = recursive_update(
+ resultset => $related_resultset,
+ updates => $sub_updates,
+ resolved => $resolved
+ );
+
+ push @updated_objs, $sub_object;
+ }
+
+ #warn "\tcreated and updated related rows\n";
+
+ my @related_pks = $related_resultset->result_source->primary_columns;
+
+ my $rs_rel_delist = $object->$name;
+
+ # foreign table has a single pk column
+ if ( scalar @related_pks == 1 ) {
+ $rs_rel_delist = $rs_rel_delist->search_rs(
+ { $related_pks[0] =>
+ { -not_in => [ map ( $_->id, @updated_objs ) ] }
+ }
+ );
+ }
+
+ # foreign table has multiple pk columns
+ else {
+ my @cond;
+ for my $obj (@updated_objs) {
+ my %cond_for_obj;
+ for my $col (@related_pks) {
+ $cond_for_obj{$col} = $obj->get_column($col);
+ }
+ push @cond, \%cond_for_obj;
+ }
+
+ # only limit resultset if there are related rows left
+ if ( scalar @cond ) {
+ $rs_rel_delist =
+ $rs_rel_delist->search_rs( { -not => [@cond] } );
+ }
+ }
+
+ #warn "\tCOND: " . Dumper(\%cond);
+ #my $rel_delist_cnt = $rs_rel_delist->count;
+ if ( $if_not_submitted eq 'delete' ) {
+
+ #warn "\tdeleting related rows: $rel_delist_cnt\n";
+ $rs_rel_delist->delete;
+ }
+ elsif ( $if_not_submitted eq 'set_to_null' ) {
+
+ #warn "\tnullifying related rows: $rel_delist_cnt\n";
+ my %update = map { $_ => undef } @rel_cols;
+ $rs_rel_delist->update( \%update );
+ }
+ }
+ elsif ($info->{attrs}{accessor} eq 'single'
+ || $info->{attrs}{accessor} eq 'filter' )
+ {
+
+ #warn "\tupdating rel '$name': $if_not_submitted\n";
+ my $sub_object;
+ if ( ref $updates ) {
+ if ( blessed($updates) && $updates->isa('DBIx::Class::Row') ) {
+ $sub_object = $updates;
+ }
+
+ # for might_have relationship
+ elsif ( $info->{attrs}{accessor} eq 'single'
+ && defined $object->$name )
+ {
+ $sub_object = recursive_update(
+ resultset => $related_resultset,
+ updates => $updates,
+ object => $object->$name
+ );
+ }
+ else {
+ $sub_object = recursive_update(
+ resultset => $related_resultset,
+ updates => $updates,
+ resolved => $resolved
+ );
+ }
+ }
+ else {
+ $sub_object = $related_resultset->find($updates)
+ unless (
+ !$updates
+ && ( exists $info->{attrs}{join_type}
+ && $info->{attrs}{join_type} eq 'LEFT' )
+ );
+ }
+ $object->set_from_related( $name, $sub_object )
+ unless (
+ !$sub_object
+ && !$updates
+ && ( exists $info->{attrs}{join_type}
+ && $info->{attrs}{join_type} eq 'LEFT' )
+ );
+ }
+ else {
+ $self->throw_exception(
+ "recursive_update doesn't now how to handle relationship '$name' with accessor "
+ . $info->{attrs}{accessor} );
+ }
+}