returned from storage
- Custom condition relationships are now invoked with a slightly
different signature (existing coderefs will continue to work)
- - Add extra custom condition coderef attribute 'foreign_resultobj'
+ - Add extra custom condition coderef attribute 'foreign_result_object'
to allow for proper reverse-relationship emulation
- (i.e. $result->set_from_related($custom_cond, $foreign_resultobj)
+ (i.e. $result->set_from_related($custom_rel, $foreign_result_object)
- When in a transaction, DBIC::Ordered now seamlesly handles result
objects that went out of sync with the storage (RT#96499)
elect to additionally return a simplified join-free condition hashref when
invoked as C<< $result->relationship >>, as opposed to
C<< $rs->related_resultset('relationship') >>. In this case C<$result> is
-passed to the coderef as C<< $args->{self_resultobj} >>, so a user can do the
+passed to the coderef as C<< $args->{self_result_object} >>, so a user can do the
following:
sub {
"$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
"$args->{foreign_alias}.year" => { '>', "1979", '<', "1990" },
},
- $args->{self_resultobj} && {
- "$args->{foreign_alias}.artist" => $args->{self_resultobj}->artistid,
+ $args->{self_result_object} && {
+ "$args->{foreign_alias}.artist" => $args->{self_result_object}->artistid,
"$args->{foreign_alias}.year" => { '>', "1979", '<', "1990" },
},
);
metadata. Currently the supplied coderef is executed as:
$relationship_info->{cond}->({
- self_resultsource => The resultsource instance on which rel_name is registered
- rel_name => The relationship name (does *NOT* always match foreign_alias)
+ self_resultsource => The resultsource instance on which rel_name is registered
+ rel_name => The relationship name (does *NOT* always match foreign_alias)
- self_alias => The alias of the invoking resultset
- foreign_alias => The alias of the to-be-joined resultset (does *NOT* always match rel_name)
+ self_alias => The alias of the invoking resultset
+ foreign_alias => The alias of the to-be-joined resultset (does *NOT* always match rel_name)
# only one of these (or none at all) will ever be supplied to aid in the
# construction of a join-free condition
- self_resultobj => The invocant object itself in case of a $resultobj->$rel_name() call
- foreign_resultobj => The related object in case of $resultobj->set_from_related($rel_name, $foreign_resultobj)
+ self_result_object => The invocant object itself in case of a $result_object->$rel_name( ... ) call
+ foreign_result_object => The related object in case of $result_object->set_from_related( $rel_name, $foreign_result_object )
# deprecated inconsistent names, will be forever available for legacy code
- self_rowobj => Old deprecated slot for self_resultobj
- foreign_relname => Old deprecated slot for rel_name
+ self_rowobj => Old deprecated slot for self_result_object
+ foreign_relname => Old deprecated slot for rel_name
});
=head3 attributes
return $self->search_related($rel)->new_result( $self->result_source->_resolve_relationship_condition (
infer_values_based_on => $data,
rel_name => $rel,
- self_resultobj => $self,
+ self_result_object => $self,
foreign_alias => $rel,
self_alias => 'me',
)->{inferred_values} );
$self->set_columns( $self->result_source->_resolve_relationship_condition (
infer_values_based_on => {},
rel_name => $rel,
- foreign_resultobj => $f_obj,
+ foreign_result_object => $f_obj,
foreign_alias => $rel,
self_alias => 'me',
)->{inferred_values} );
# where-is-waldo block guesses relname, then further down we override it if available
(
- $is_objlike[1] ? ( rel_name => $res_args[0], self_alias => $res_args[0], foreign_alias => 'me', self_resultobj => $res_args[1] )
- : $is_objlike[0] ? ( rel_name => $res_args[1], self_alias => 'me', foreign_alias => $res_args[1], foreign_resultobj => $res_args[0] )
+ $is_objlike[1] ? ( rel_name => $res_args[0], self_alias => $res_args[0], foreign_alias => 'me', self_result_object => $res_args[1] )
+ : $is_objlike[0] ? ( rel_name => $res_args[1], self_alias => 'me', foreign_alias => $res_args[1], foreign_result_object => $res_args[0] )
: ( rel_name => $res_args[0], self_alias => $res_args[1], foreign_alias => $res_args[0] )
),
## self-explanatory API, modeled on the custom cond coderef:
# rel_name
# foreign_alias
-# foreign_resultobj
+# foreign_result_object
# self_alias
-# self_resultobj
+# self_result_object
# require_join_free_condition
# infer_values_based_on (optional, mandatory hashref argument)
# condition (optional, derived from $self->rel_info(rel_name))
or $self->throw_exception( "No such $exception_rel_id" );
$self->throw_exception("No practical way to resolve $exception_rel_id between two data structures")
- if defined $args->{self_resultobj} and defined $args->{foreign_resultobj};
+ if defined $args->{self_result_object} and defined $args->{foreign_result_object};
$self->throw_exception( "Argument to infer_values_based_on must be a hash" )
if exists $args->{infer_values_based_on} and ref $args->{infer_values_based_on} ne 'HASH';
$args->{condition} ||= $rel_info->{cond};
- if (exists $args->{self_resultobj}) {
- if (defined blessed $args->{self_resultobj}) {
- $self->throw_exception( "Object '$args->{self_resultobj}' must be of class '@{[ $self->result_class ]}'" )
- unless $args->{self_resultobj}->isa($self->result_class);
+ if (exists $args->{self_result_object}) {
+ if (defined blessed $args->{self_result_object}) {
+ $self->throw_exception( "Object '$args->{self_result_object}' must be of class '@{[ $self->result_class ]}'" )
+ unless $args->{self_result_object}->isa($self->result_class);
}
else {
- $args->{self_resultobj} = DBIx::Class::Core->new({
+ $args->{self_result_object} = DBIx::Class::Core->new({
-result_source => $self,
- %{ $args->{self_resultobj}||{} }
+ %{ $args->{self_result_object}||{} }
});
}
}
- if (exists $args->{foreign_resultobj}) {
- if (defined blessed $args->{foreign_resultobj}) {
- $self->throw_exception( "Object '$args->{foreign_resultobj}' must be of class '$rel_info->{class}'" )
- unless $args->{foreign_resultobj}->isa($rel_info->{class});
+ if (exists $args->{foreign_result_object}) {
+ if (defined blessed $args->{foreign_result_object}) {
+ $self->throw_exception( "Object '$args->{foreign_result_object}' must be of class '$rel_info->{class}'" )
+ unless $args->{foreign_result_object}->isa($rel_info->{class});
}
else {
- $args->{foreign_resultobj} = DBIx::Class::Core->new({
+ $args->{foreign_result_object} = DBIx::Class::Core->new({
-result_source => $self->related_source($args->{rel_name}),
- %{ $args->{foreign_resultobj}||{} }
+ %{ $args->{foreign_result_object}||{} }
});
}
}
foreign_alias => $args->{foreign_alias},
( map
{ (exists $args->{$_}) ? ( $_ => $args->{$_} ) : () }
- qw( self_resultobj foreign_resultobj )
+ qw( self_result_object foreign_result_object )
),
};
# legacy - never remove these!!!
$cref_args->{foreign_relname} = $cref_args->{rel_name};
- $cref_args->{self_rowobj} = $cref_args->{self_resultobj}
- if exists $cref_args->{self_resultobj};
+ $cref_args->{self_rowobj} = $cref_args->{self_result_object}
+ if exists $cref_args->{self_result_object};
($ret->{condition}, $ret->{join_free_condition}, my @extra) = $args->{condition}->($cref_args);
) unless ref $jfc eq 'HASH';
my ($joinfree_alias, $joinfree_source);
- if (defined $args->{self_resultobj}) {
+ if (defined $args->{self_result_object}) {
$joinfree_alias = $args->{foreign_alias};
$joinfree_source = $self->related_source($args->{rel_name});
}
- elsif (defined $args->{foreign_resultobj}) {
+ elsif (defined $args->{foreign_result_object}) {
$joinfree_alias = $args->{self_alias};
$joinfree_source = $self;
}
$ret->{identity_map}{$l_cols[$_]} = $f_cols[$_];
};
- if (exists $args->{self_resultobj} or exists $args->{foreign_resultobj}) {
+ if (exists $args->{self_result_object} or exists $args->{foreign_result_object}) {
- my ($obj, $obj_alias, $plain_alias, $obj_cols, $plain_cols) = defined $args->{self_resultobj}
- ? ( @{$args}{qw( self_resultobj self_alias foreign_alias )}, \@l_cols, \@f_cols )
- : ( @{$args}{qw( foreign_resultobj foreign_alias self_alias )}, \@f_cols, \@l_cols )
+ my ($obj, $obj_alias, $plain_alias, $obj_cols, $plain_cols) = defined $args->{self_result_object}
+ ? ( @{$args}{qw( self_result_object self_alias foreign_alias )}, \@l_cols, \@f_cols )
+ : ( @{$args}{qw( foreign_result_object foreign_alias self_alias )}, \@f_cols, \@l_cols )
;
for my $i (0..$#$obj_cols) {
if (
- defined $args->{self_resultobj}
+ defined $args->{self_result_object}
and
! $obj->has_column_loaded($obj_cols->[$i])
) {
return (
{ "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} },
},
- $args->{self_resultobj} && {
- "$args->{foreign_alias}.artist" => $args->{self_resultobj}->artistid,
+ $args->{self_result_object} && {
+ "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, # keep old rowobj syntax as a test
}
);
},
{ "$args->{foreign_alias}.artist" => { '=' => \ "$args->{self_alias}.artistid" },
"$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
},
- $args->{self_resultobj} && {
- "$args->{foreign_alias}.artist" => { '=' => \[ '?', $args->{self_resultobj}->artistid ] },
+ $args->{self_result_object} && {
+ "$args->{foreign_alias}.artist" => { '=' => \[ '?', $args->{self_result_object}->artistid ] },
"$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
}
);
{ "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
"$args->{foreign_alias}.year" => 1984,
},
- $args->{self_resultobj} && {
- "$args->{foreign_alias}.artist" => $args->{self_resultobj}->artistid,
+ $args->{self_result_object} && {
+ "$args->{foreign_alias}.artist" => $args->{self_result_object}->artistid,
"$args->{foreign_alias}.year" => 1984,
}
);
{
"$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
"$args->{foreign_alias}.genreid" => undef,
- }, $args->{self_resultobj} && {
- "$args->{foreign_alias}.artist" => $args->{self_resultobj}->artistid,
+ }, $args->{self_result_object} && {
+ "$args->{foreign_alias}.artist" => $args->{self_result_object}->artistid,
"$args->{foreign_alias}.genreid" => undef,
}
),
return (
{ "$args->{foreign_alias}.artwork_cd_id" => { -ident => "$args->{self_alias}.cd_id" },
},
- $args->{self_resultobj} && {
- "$args->{foreign_alias}.artwork_cd_id" => $args->{self_resultobj}->cd_id,
+ $args->{self_result_object} && {
+ "$args->{foreign_alias}.artwork_cd_id" => $args->{self_result_object}->cd_id,
}
);
}
{ "$args->{foreign_alias}.artistid" => { -ident => "$args->{self_alias}.artist_id" },
"$args->{foreign_alias}.rank" => { '<' => 10 },
},
- $args->{self_resultobj} && {
- "$args->{foreign_alias}.artistid" => $args->{self_resultobj}->artist_id,
+ $args->{self_result_object} && {
+ "$args->{foreign_alias}.artistid" => $args->{self_result_object}->artist_id,
"$args->{foreign_alias}.rank" => { '<' => 10 },
}
);
"$args->{foreign_alias}.cdid" => { -ident => "$args->{self_alias}.cd" },
},
- ( $args->{self_resultobj} ? {
- "$args->{foreign_alias}.cdid" => $args->{self_resultobj}->cd
+ ( $args->{self_result_object} ? {
+ "$args->{foreign_alias}.cdid" => $args->{self_result_object}->cd
} : () ),
- ( $args->{foreign_resultobj} ? {
- "$args->{self_alias}.cd" => $args->{foreign_resultobj}->cdid
+ ( $args->{foreign_result_object} ? {
+ "$args->{self_alias}.cd" => $args->{foreign_result_object}->cdid
} : () ),
);
}
{ "$args->{foreign_alias}.cd" => { -ident => "$args->{self_alias}.cd" },
"$args->{foreign_alias}.position" => { '>' => { -ident => "$args->{self_alias}.position" } },
},
- $args->{self_resultobj} && {
- "$args->{foreign_alias}.cd" => $args->{self_resultobj}->get_column('cd'),
- "$args->{foreign_alias}.position" => { '>' => $args->{self_resultobj}->pos },
+ $args->{self_result_object} && {
+ "$args->{foreign_alias}.cd" => $args->{self_result_object}->get_column('cd'),
+ "$args->{foreign_alias}.position" => { '>' => $args->{self_result_object}->pos },
}
)
}
my $rowobj_cnt = 0;
- if (defined $args->{self_resultobj} or defined $args->{self_rowobj} ) {
+ if (defined $args->{self_result_object} or defined $args->{self_rowobj} ) {
$rowobj_cnt++;
- for (qw(self_resultobj self_rowobj)) {
+ for (qw(self_result_object self_rowobj)) {
confess "Custom condition argument '$_' must be a result instance"
unless defined blessed $args->{$_} and $args->{$_}->isa('DBIx::Class::Row');
}
- confess "Current and legacy self_resultobj arguments do not match"
- if refaddr($args->{self_resultobj}) != refaddr($args->{self_rowobj});
+ confess "Current and legacy self_result_object arguments do not match"
+ if refaddr($args->{self_result_object}) != refaddr($args->{self_rowobj});
}
- if (defined $args->{foreign_resultobj}) {
+ if (defined $args->{foreign_result_object}) {
$rowobj_cnt++;
- confess "Custom condition argument 'foreign_resultobj' must be a result instance"
- unless defined blessed $args->{foreign_resultobj} and $args->{foreign_resultobj}->isa('DBIx::Class::Row');
+ confess "Custom condition argument 'foreign_result_object' must be a result instance"
+ unless defined blessed $args->{foreign_result_object} and $args->{foreign_result_object}->isa('DBIx::Class::Row');
}
confess "Result objects supplied on both ends of a relationship"