Skip to content

Commit

Permalink
Rename (with a silent compat shim) couple of badly named customcond args
Browse files Browse the repository at this point in the history
foreign_relname makes absolutely no sense - it *is* a relationship after all,
of course it has a name. Now renamed to rel_name to be consistent with
the relationship condition resolver

self_rowobj uses the old rowobj nomenclature - switch to self_resultobj
  • Loading branch information
ribasushi committed Jun 11, 2014
1 parent a3a17a1 commit a446d7f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Revision history for DBIx::Class
like the rest of DBIC
- DBIC::FilterColumn "from_storage" handler is now invoked on NULLs
returned from storage
- Custom condition relationships are now invoked with a slightly
different signature (existing coderefs will continue to work)

* Fixes
- Fix Resultset delete/update affecting *THE ENTIRE TABLE* in cases
Expand Down
16 changes: 11 additions & 5 deletions lib/DBIx/Class/Relationship/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,17 @@ clause, the C<$args> hashref passed to the subroutine contains some extra
metadata. Currently the supplied coderef is executed as:
$relationship_info->{cond}->({
self_alias => The alias of the invoking resultset ('me' in case of a result object),
foreign_alias => The alias of the to-be-joined resultset (often matches relname),
self_resultsource => The invocant's resultsource,
foreign_relname => The relationship name (does *not* always match foreign_alias),
self_rowobj => The invocant itself in case of a $result_object->$relationship call
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_resultobj => The invocant object itself in case of a $resultobj->$rel_name() call
# 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
});
=head3 attributes
Expand Down
2 changes: 1 addition & 1 deletion lib/DBIx/Class/ResultSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@ sub populate {
foreach my $rel (@rels) {
next unless ref $data->[$index]->{$rel} eq "HASH";
my $result = $self->related_resultset($rel)->create($data->[$index]->{$rel});
my ($reverse_relname, $reverse_relinfo) = %{$rsrc->reverse_relationship_info($rel)};
my (undef, $reverse_relinfo) = %{$rsrc->reverse_relationship_info($rel)};
my $related = $result->result_source->_resolve_condition(
$reverse_relinfo->{cond},
$self,
Expand Down
18 changes: 12 additions & 6 deletions lib/DBIx/Class/ResultSource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1771,20 +1771,26 @@ sub _resolve_relationship_condition {

if (ref $args->{condition} eq 'CODE') {

my ($crosstable_cond, $joinfree_cond) = $args->{condition}->({
my $cref_args = {
rel_name => $args->{rel_name},
self_resultsource => $self,
self_alias => $args->{self_alias},
foreign_alias => $args->{foreign_alias},
self_resultsource => $self,
foreign_relname => $args->{rel_name},
self_rowobj => defined $args->{self_resultobj} ? $args->{self_resultobj} : undef,
});
self_resultobj => defined $args->{self_resultobj} ? $args->{self_resultobj} : undef,
};

# legacy - never remove these!!!
$cref_args->{foreign_relname} = $cref_args->{rel_name};
$cref_args->{self_rowobj} = $cref_args->{self_resultobj};

my ($crosstable_cond, $joinfree_cond) = $args->{condition}->($cref_args);

my @nonvalue_cols;
if ($joinfree_cond) {

# FIXME sanity check until things stabilize, remove at some point
$self->throw_exception (
"A join-free condition returned for relationship '$args->{rel_name}' without a row-object to chain from"
"A join-free condition returned for relationship '$args->{rel_name}' without a result object to chain from"
) unless defined $args->{self_resultobj};

my $foreign_src_fq_col_list = { map { ( "$args->{foreign_alias}.$_" => 1 ) } $self->related_source($args->{rel_name})->columns };
Expand Down
20 changes: 14 additions & 6 deletions t/lib/DBICTest/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use strict;

use Config;
use Carp 'confess';
use Scalar::Util 'blessed';
use Scalar::Util qw(blessed refaddr);

use base 'Exporter';
our @EXPORT_OK = qw(local_umask stacktrace check_customcond_args);
Expand Down Expand Up @@ -52,20 +52,28 @@ sub check_customcond_args ($) {
confess "Expecting a hashref"
unless ref $args eq 'HASH';

for (qw(foreign_relname self_alias foreign_alias)) {
for (qw(rel_name foreign_relname self_alias foreign_alias)) {
confess "Custom condition argument '$_' must be a plain string"
if length ref $args->{$_} or ! length $args->{$_};
}

confess "Current and legacy rel_name arguments do not match"
if $args->{rel_name} ne $args->{foreign_relname};

confess "Custom condition argument 'self_resultsource' must be a rsrc instance"
unless defined blessed $args->{self_resultsource} and $args->{self_resultsource}->isa('DBIx::Class::ResultSource');

confess "Passed resultsource has no record of the supplied rel_name - likely wrong \$rsrc"
unless ref $args->{self_resultsource}->relationship_info($args->{foreign_relname});
unless ref $args->{self_resultsource}->relationship_info($args->{rel_name});

if (defined $args->{self_resultobj} or defined $args->{self_rowobj} ) {
for (qw(self_resultobj self_rowobj)) {
confess "Custom condition argument '$_' must be a result instance"
unless defined blessed $args->{$_} and $args->{$_}->isa('DBIx::Class::Row');
}

if (defined $args->{self_rowobj}) {
confess "Custom condition argument 'self_rowobj' must be a result instance"
unless defined blessed $args->{self_rowobj} and $args->{self_rowobj}->isa('DBIx::Class::Row');
confess "Current and legacy self_resultobj arguments do not match"
if refaddr($args->{self_resultobj}) != refaddr($args->{self_rowobj});
}

$args;
Expand Down

0 comments on commit a446d7f

Please sign in to comment.