my ($key, $value) = ($flattened->[$i], $flattened->[$i+1]);
my ($type, $op) = $key =~ m{:(.+)::(.+)};
- ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } });
- ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } });
- ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class};
- ($key, $value) = _apply_value_filters($key, $value, $type, $op);
+ if ($key =~ s/:multi//) {
+ my @multi;
+ my $orig_key = $key;
+ for my $value (split / /, $value) {
+ ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } });
+ ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } });
+ ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class};
+ ($key, $value) = _apply_value_filters($key, $value, $type, $op);
+ push @multi, $key, $value;
+ $key = $orig_key;
+ }
+ ($key, $value) = (and => \@multi);
+ } else {
+ ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } });
+ ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } });
+ ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class};
+ ($key, $value) = _apply_value_filters($key, $value, $type, $op);
+ }
push @result, $key, $value if defined $key;
}
use lib 't';
-use Test::More tests => 28;
+use Test::More tests => 30;
use Test::Deep;
use Data::Dumper;
}
]
}, 'Regression check: prefixing of fallback filtering in relation with custom filters', class => 'SL::DB::Manager::OrderItem';
+test {
+ 'description:substr:multi::ilike' => 'term1 term2',
+}, {
+ query => [
+ and => [
+ description => { ilike => '%term1%' },
+ description => { ilike => '%term2%' },
+ ]
+ ]
+}, 'simple :multi';
+
+test {
+ part => {
+ 'all:substr:multi::ilike' => 'term1 term2',
+ },
+}, {
+ query => [
+ and => [
+ or => [
+ 'part.partnumber' => { ilike => '%term1%' },
+ 'part.description' => { ilike => '%term1%' },
+ ],
+ or => [
+ 'part.partnumber' => { ilike => '%term2%' },
+ 'part.description' => { ilike => '%term2%' },
+ ],
+ ]
+ ],
+}, 'complex :multi with custom dispatch and prefix', class => 'SL::DB::Manager::OrderItem';