From: Matt S Trout Date: Sun, 17 Nov 2013 03:25:57 +0000 (+0000) Subject: fix unresolvable condition handling X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9ece2795fe1a4c7a17b3735fd1a56ac6aaa58054;p=dbsrgits%2FDBIx-Class.git fix unresolvable condition handling --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 3b1f849..846922e 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -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( diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index ea0adac..e9b0f25 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -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