Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow same 'key' to be used for same attribute

  • Loading branch information...
commit 87a59ca146268463f6cb18e777dcc05015efcbfc 1 parent 123fb96
@ginesr authored
Showing with 27 additions and 3 deletions.
  1. +12 −2 lib/Gideon.pm
  2. +15 −1 t/05filters.t
View
14 lib/Gideon.pm
@@ -232,7 +232,7 @@ sub decode_params {
$args->{$_} = \@all;
}
}
-
+
return wantarray ? ( $args, $config ) : $args;
}
@@ -251,8 +251,12 @@ sub trans_filters {
if ( ref($filter) eq 'ARRAY' ) {
my @multi = ();
foreach ( @{$filter} ) {
- my @filters = $class->_transform_filter( $_, @filters );
my @pairs = ();
+ if ( !ref( $_ ) ) {
+ push @multi, $_;
+ next;
+ }
+ my @filters = $class->_transform_filter( $_, @filters );
foreach my $f (@filters) {
foreach my $h ( keys %{$f} ) {
push @pairs, ( $h, $f->{$h} );
@@ -715,10 +719,16 @@ sub _transform_filter {
my $class = shift;
my $filter = shift;
my @filters = @_;
+
+ unless ( ref $filter eq 'HASH' ) {
+ push @filters, $filter;
+ return @filters;
+ }
my %map = (
'like' => '-like',
'eq' => '=',
+ '=' => '=',
'gt' => '>',
'lt' => '<',
'not' => '!',
View
16 t/05filters.t
@@ -2,7 +2,7 @@
use lib 'xlib';
use strict;
-use Test::More tests => 8;
+use Test::More tests => 9;
use Gideon;
use Data::Dumper qw(Dumper);
use DBD::Mock;
@@ -61,6 +61,13 @@ my $mock_session = DBD::Mock::Session->new(
bound_params => [ 'Argentina', 'Uruguay' ],
results => [ [ 'country.country_iso', 'country.country_name' ], [ 'AR', 'Argentina' ], [ 'UY', 'Uruguay' ] ]
+ },
+ {
+ statement =>
+ 'SELECT country.country_iso as `country.country_iso`, country.country_name as `country.country_name` FROM country WHERE ( ( country.country_name = ? OR country.country_name = ? ) )',
+ bound_params => [ 'Argentina', 'Uruguay' ],
+ results => [ [ 'country.country_iso', 'country.country_name' ], [ 'AR', 'Argentina' ], [ 'UY', 'Uruguay' ] ]
+
}
);
$dbh->{mock_session} = $mock_session;
@@ -126,3 +133,10 @@ lives_ok(
'One eq filter with multiple values produces: country_name = ? OR country_name = ?'
);
+lives_ok(
+ sub {
+ $record = Example::Country->find_all( name => 'Argentina', name => 'Uruguay' );
+ },
+ 'Two filters without operands produces: country_name = ? OR country_name = ?'
+);
+
Please sign in to comment.
Something went wrong with that request. Please try again.