From 84c2b3f270aa65978d03f82cde8136f6764406a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 10 Apr 2015 14:05:24 +0200 Subject: [PATCH] ParseFilter: typo + test --- SL/Controller/Helper/ParseFilter.pm | 15 +++++++++++++-- t/controllers/helpers/parse_filter.t | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/SL/Controller/Helper/ParseFilter.pm b/SL/Controller/Helper/ParseFilter.pm index c38974e40..cdd3eb7a7 100644 --- a/SL/Controller/Helper/ParseFilter.pm +++ b/SL/Controller/Helper/ParseFilter.pm @@ -151,11 +151,22 @@ sub _dispatch_custom_filters { my @tokens = split /\./, $key; my $curr_class = $class->object_class; - # find first token which is not a relationship + # our key will consist of dot-delimited tokens + # like this: order.part.unit.name + # each of these tokens except the last one is one of: + # - a relationship in the parent object + # - a custom filter + # + # the last token must be + # - a custom filter + # - a column in the parent object + # + # find first token which is not a relationship, + # so we can pass the rest on my $i = 0; while ($i < $#tokens) { eval { - $curr_class = $curr_class->meta->relationship($tokens[$_])->class; + $curr_class = $curr_class->meta->relationship($tokens[$i])->class; ++$i; } or do { last; diff --git a/t/controllers/helpers/parse_filter.t b/t/controllers/helpers/parse_filter.t index a53c8c469..aa8856ab4 100644 --- a/t/controllers/helpers/parse_filter.t +++ b/t/controllers/helpers/parse_filter.t @@ -1,6 +1,6 @@ use lib 't'; -use Test::More tests => 36; +use Test::More tests => 37; use Test::Deep; use Data::Dumper; @@ -397,3 +397,11 @@ test { 'part.test' => { 'what', { ilike => '%2%' } }, ] }, 'additional tokens + filters + methods', class => 'SL::DB::Manager::OrderItem'; + +test { + 'orderitems.part.test.what:substr::ilike' => 2, +}, { + query => [ + 'orderitems.part.test' => { 'what', { ilike => '%2%' } }, + ] +}, 'relationship + additional tokens + filters + methods', class => 'SL::DB::Manager::Order'; -- 2.20.1