}
for my $name ( keys %pre_updates ) {
my $info = $object->result_source->relationship_info($name);
- _update_relation( $self, $name, $updates, $object, $info,
+ _update_relation( $self, $name, $updates->{$name}, $object, $info,
$if_not_submitted );
}
}
for my $name ( keys %post_updates ) {
my $info = $object->result_source->relationship_info($name);
- _update_relation( $self, $name, $updates, $object, $info,
+ _update_relation( $self, $name, $updates->{$name}, $object, $info,
$if_not_submitted );
}
return $object;
return %columns;
}
+# Arguments: $name, $updates, $object, $info, $if_not_submitted
+
sub _update_relation {
my ( $self, $name, $updates, $object, $info, $if_not_submitted ) = @_;
my $related_result =
$object );
}
- # warn 'resolved: ' . Dumper( $resolved ); use Data::Dumper;
+ # warn "$name resolved: " . Dumper( $resolved ); use Data::Dumper;
$resolved = {}
if defined $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION
&& $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION
== $resolved;
- if ( ref $updates->{$name} eq 'ARRAY' ) {
+
+ # an arrayref is only valid for has_many rels
+ if ( ref $updates eq 'ARRAY' ) {
my @updated_ids;
- for my $sub_updates ( @{ $updates->{$name} } ) {
+ for my $sub_updates ( @{ $updates } ) {
my $sub_object = recursive_update(
resultset => $related_result,
updates => $sub_updates,
}
}
else {
- my $sub_updates = $updates->{$name};
my $sub_object;
- if ( ref $sub_updates ) {
+ if ( ref $updates ) {
# for might_have relationship
if ( $info->{attrs}{accessor} eq 'single'
{
$sub_object = recursive_update(
resultset => $related_result,
- updates => $sub_updates,
+ updates => $updates,
object => $object->$name
);
}
else {
$sub_object = recursive_update(
resultset => $related_result,
- updates => $sub_updates,
+ updates => $updates,
resolved => $resolved
);
}
}
- elsif ( !ref $sub_updates ) {
- $sub_object = $related_result->find($sub_updates)
+ elsif ( !ref $updates ) {
+ $sub_object = $related_result->find($updates)
unless (
- !$sub_updates
+ !$updates
&& ( exists $info->{attrs}{join_type}
&& $info->{attrs}{join_type} eq 'LEFT' )
);
$object->set_from_related( $name, $sub_object )
unless (
!$sub_object
- && !$sub_updates
+ && !$updates
&& ( exists $info->{attrs}{join_type}
&& $info->{attrs}{join_type} eq 'LEFT' )
);
=head2 Treatment of many-to-many pseudo relations
The function gets the information about m2m relations from DBIx::Class::IntrospectableM2M.
-If it is not loaded in the ResultSource classes - then the code relies on the fact that:
+If it isn't loaded in the ResultSource classes the code relies on the fact that:
+
if($object->can($name) and
!$object->result_source->has_relationship($name) and
$object->can( 'set_' . $name )
)
-then $name must be a many to many pseudo relation. And that in a
-similarly ugly was I find out what is the ResultSource of objects from
-that many to many pseudo relation.
+Then $name must be a many to many pseudo relation.
+And that in a similarly ugly was I find out what is the ResultSource of
+objects from that many to many pseudo relation.
=head1 INTERFACE