Standardize indication of lack of join_free_condition after resolution
Peter Rabbitson [Sun, 18 Sep 2016 10:28:18 +0000 (12:28 +0200)]
There should be zero functional changes as a result

lib/DBIx/Class/Relationship/Accessor.pm
lib/DBIx/Class/Relationship/Base.pm
lib/DBIx/Class/ResultSource.pm

index 9d4d378..42d7e38 100644 (file)
@@ -63,10 +63,6 @@ sub add_relationship_accessor {
 
             and
 
-          $jfc ne DBIx::Class::_Util::UNRESOLVABLE_CONDITION
-
-            and
-
           grep { not defined $_ } values %%$jfc
         );
 
index 6453679..c4d4df5 100644 (file)
@@ -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
@@ -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,
     );
   }
 
index c8c8f2e..0d3bc34 100644 (file)
@@ -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;
         }
       }
@@ -2497,7 +2497,6 @@ sub _resolve_relationship_condition {
     if (@{ $rel_info->{cond} } == 0) {
       $ret = {
         condition => UNRESOLVABLE_CONDITION,
-        join_free_condition => UNRESOLVABLE_CONDITION,
       };
     }
     else {
@@ -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",
@@ -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},
@@ -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 "