Skip to content

Commit

Permalink
Standardize indication of lack of join_free_condition after resolution
Browse files Browse the repository at this point in the history
There should be zero functional changes as a result
  • Loading branch information
ribasushi committed Sep 27, 2016
1 parent 09d2e66 commit ea3ee77
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
4 changes: 0 additions & 4 deletions lib/DBIx/Class/Relationship/Accessor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ sub add_relationship_accessor {
and
$jfc ne DBIx::Class::_Util::UNRESOLVABLE_CONDITION
and
grep { not defined $_ } values %%$jfc
);
Expand Down
41 changes: 19 additions & 22 deletions lib/DBIx/Class/Relationship/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,14 @@ sub related_resultset {

my $rel_rset;

if (
! $jfc
and
$relcond_is_freeform
) {
if( defined $jfc ) {

$rel_rset = $rsrc->related_source($rel)->resultset->search(
$jfc,
$rel_info->{attrs},
);
}
elsif( $relcond_is_freeform ) {

# A WHOREIFFIC hack to reinvoke the entire condition resolution
# with the correct alias. Another way of doing this involves a
Expand Down Expand Up @@ -577,25 +580,19 @@ sub related_resultset {
}
else {

# FIXME - this conditional doesn't seem correct - got to figure out
# at some point what it does. Also the entire UNRESOLVABLE_CONDITION
# business seems shady - we could simply not query *at all*
my $attrs;
if ( $jfc eq UNRESOLVABLE_CONDITION ) {
$attrs = { %{$rel_info->{attrs}} };
my $reverse = $rsrc->reverse_relationship_info($rel);
foreach my $rev_rel (keys %$reverse) {
if ($reverse->{$rev_rel}{attrs}{accessor} && $reverse->{$rev_rel}{attrs}{accessor} eq 'multi') {
weaken($attrs->{related_objects}{$rev_rel}[0] = $self);
} else {
weaken($attrs->{related_objects}{$rev_rel} = $self);
}
}
}
my $attrs = { %{$rel_info->{attrs}} };
my $reverse = $rsrc->reverse_relationship_info($rel);

# FIXME - this loop doesn't seem correct - got to figure out
# at some point what exactly it does.
( ( $reverse->{$_}{attrs}{accessor}||'') eq 'multi' )
? weaken( $attrs->{related_objects}{$_}[0] = $self )
: weaken( $attrs->{related_objects}{$_} = $self )
for keys %$reverse;

$rel_rset = $rsrc->related_source($rel)->resultset->search(
$jfc,
$attrs || $rel_info->{attrs},
UNRESOLVABLE_CONDITION, # guards potential use of the $rs in the future
$attrs,
);
}

Expand Down
13 changes: 4 additions & 9 deletions lib/DBIx/Class/ResultSource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2487,7 +2487,7 @@ sub _resolve_relationship_condition {

# FIXME - temporarly force-override
delete $args->{require_join_free_condition};
$ret->{join_free_condition} = UNRESOLVABLE_CONDITION;
delete $ret->{join_free_condition};
last;
}
}
Expand All @@ -2497,7 +2497,6 @@ sub _resolve_relationship_condition {
if (@{ $rel_info->{cond} } == 0) {
$ret = {
condition => UNRESOLVABLE_CONDITION,
join_free_condition => UNRESOLVABLE_CONDITION,
};
}
else {
Expand Down Expand Up @@ -2541,7 +2540,7 @@ sub _resolve_relationship_condition {
if (
$args->{require_join_free_condition}
and
( ! $ret->{join_free_condition} or $ret->{join_free_condition} eq UNRESOLVABLE_CONDITION )
! defined $ret->{join_free_condition}
) {
$self->throw_exception(
ucfirst sprintf "$exception_rel_id does not resolve to a %sjoin-free condition fragment",
Expand All @@ -2553,11 +2552,7 @@ sub _resolve_relationship_condition {

# we got something back - sanity check and infer values if we can
my @nonvalues;
if (
$ret->{join_free_condition}
and
$ret->{join_free_condition} ne UNRESOLVABLE_CONDITION
) {
if( $ret->{join_free_condition} ) {

my $jfc_eqs = extract_equality_conditions(
$ret->{join_free_condition},
Expand All @@ -2569,7 +2564,7 @@ sub _resolve_relationship_condition {
push @nonvalues, { $_ => $ret->{join_free_condition}{$_} };
}
else {
# a join_free_condoition is fully qualified by definition
# a join_free_condition is fully qualified by definition
my ($col) = $_ =~ /\.(.+)/ or carp_unique(
'Internal error - extract_equality_conditions() returned a '
. "non-fully-qualified key '$_'. *Please* file a bugreport "
Expand Down

0 comments on commit ea3ee77

Please sign in to comment.