From: Peter Rabbitson Date: Sat, 20 Aug 2016 09:09:39 +0000 (+0200) Subject: Fix SQLA condition normalizer sometimes stripping -value ops X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aa072cab54f2e6af9a9db82b3cdec0ebb97717cc;p=dbsrgits%2FDBIx-Class.git Fix SQLA condition normalizer sometimes stripping -value ops --- diff --git a/lib/DBIx/Class/SQLMaker/Util.pm b/lib/DBIx/Class/SQLMaker/Util.pm index ec83edd..e538843 100644 --- a/lib/DBIx/Class/SQLMaker/Util.pm +++ b/lib/DBIx/Class/SQLMaker/Util.pm @@ -348,7 +348,11 @@ sub _normalize_cond_unroll_pairs { and my $vref = is_plain_value( (values %$rhs)[0] ) ) { - push @conds, { $lhs => { $subop => $$vref } } + push @conds, ( + (length ref $$vref) + ? { $lhs => $rhs } + : { $lhs => { $subop => $$vref } } + ); } else { push @conds, { $lhs => $rhs }; diff --git a/xt/extra/internals/sqla_condition_parsers.t b/xt/extra/internals/sqla_condition_parsers.t index 5c94edc..14a2c31 100644 --- a/xt/extra/internals/sqla_condition_parsers.t +++ b/xt/extra/internals/sqla_condition_parsers.t @@ -273,14 +273,17 @@ my @tests = ( charfield => { -ident => 'foo' }, name => { '=' => { -value => undef } }, rank => { '=' => { -ident => 'bar' } }, + arrayfield => { '>' => { -value => [3,1] } }, ] }, - sql => 'WHERE artistid = ? AND charfield = foo AND name IS NULL AND rank = bar', normalized => { artistid => { -value => [1] }, name => undef, charfield => { '=', { -ident => 'foo' } }, rank => { '=' => { -ident => 'bar' } }, + arrayfield => { '>' => { -value => [3,1] } }, }, + sql => 'WHERE artistid = ? AND charfield = foo AND name IS NULL AND rank = bar AND arrayfield > ?', + normalized_sql => 'WHERE arrayfield > ? AND artistid = ? AND charfield = foo AND name IS NULL AND rank = bar', equality_extract => { artistid => [1], charfield => { -ident => 'foo' }, @@ -682,4 +685,10 @@ for my $t (@tests) { } } +# test separately +is_deeply( + normalize_sqla_condition( UNRESOLVABLE_CONDITION ), + { -and => [ UNRESOLVABLE_CONDITION ] }, +); + done_testing;