fix unresolvable condition handling
Matt S Trout [Sun, 17 Nov 2013 03:25:57 +0000 (03:25 +0000)]
lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/ResultSource.pm

index 3b1f849..846922e 100644 (file)
@@ -604,6 +604,8 @@ sub _stack_cond {
 
   my @uniq = grep { !$seen{Data::Dumper::Concise::Dumper($_)}++ } @top;
 
+  return \$uniq[0] if @uniq == 1;
+
   return \Operator({ 'SQL.Naive' => 'AND' }, \@uniq);
 }
 
@@ -2477,10 +2479,6 @@ sub _merge_with_rscond {
   if (! defined $self->{cond}) {
     # just massage $data below
   }
-  elsif ($self->{cond} eq $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION) {
-    %new_data = %{ $self->{attrs}{related_objects} || {} };  # nothing might have been inserted yet
-    @cols_from_relations = keys %new_data;
-  }
   elsif (ref $self->{cond} eq 'HASH') {
     # precedence must be given to passed values over values inherited from
     # the cond, so the order here is important.
@@ -2504,11 +2502,16 @@ sub _merge_with_rscond {
     }
   }
   elsif (ref $self->{cond} eq 'REF' and ref ${$self->{cond}} eq 'HASH') {
-    %new_data = %{$self->_remove_alias(
-      $self->result_source
-           ->_extract_fixed_values_for(${$self->{cond}}),
-      $alias
-    )};
+    if ((${$self->{cond}})->{'DBIx::Class::ResultSource.UNRESOLVABLE'}) {
+      %new_data = %{ $self->{attrs}{related_objects} || {} };  # nothing might have been inserted yet
+      @cols_from_relations = keys %new_data;
+    } else {
+      %new_data = %{$self->_remove_alias(
+        $self->result_source
+             ->_extract_fixed_values_for(${$self->{cond}}),
+        $alias
+      )};
+    }
   }
   else {
     $self->throw_exception(
index ea0adac..e9b0f25 100644 (file)
@@ -1782,7 +1782,9 @@ sub resolve_condition {
   $self->_resolve_condition (@_);
 }
 
-our $UNRESOLVABLE_CONDITION = \ '1 = 0';
+our $UNRESOLVABLE_CONDITION = \Literal(SQL => '1 = 0');
+
+${$UNRESOLVABLE_CONDITION}->{'DBIx::Class::ResultSource.UNRESOLVABLE'} = 1;
 
 # Resolves the passed condition to a concrete query fragment and a flag
 # indicating whether this is a cross-table condition. Also an optional