_add_uniq($objects, $_) for @$auto_objects;
}
- my $query = _parse_filter($flattened, $objects, %params);
-
_launder_keys($filter, $params{launder_to}) unless $params{no_launder};
+ my $query = _parse_filter($flattened, $objects, %params);
+
return
($query && @$query ? (query => $query) : ()),
($objects && @$objects ? ( with_objects => [ uniq @$objects ]) : ());
die 'unrecognized filters' if $key =~ /:/;
my @tokens = split /\./, $key;
- my $last_token = pop @tokens;
my $curr_class = $class->object_class;
- for my $token (@tokens) {
+ # 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($token)->class;
- 1;
+ $curr_class = $curr_class->meta->relationship($tokens[$i])->class;
+ ++$i;
} or do {
- require Carp;
- Carp::croak("Could not resolve the relationship '$token' in '$key' while building the filter request");
+ last;
}
}
my $manager = $curr_class->meta->convention_manager->auto_manager_class_name;
- my $obj_path = join '.', @tokens;
- my $obj_prefix = join '.', @tokens, '';
+ my $obj_path = join '.', @tokens[0..$i-1];
+ my $obj_prefix = join '.', @tokens[0..$i-1], '';
+ my $key_token = $tokens[$i];
+ my @additional_tokens = @tokens[$i+1..$#tokens];
if ($manager->can('filter')) {
- ($key, $value, my $obj) = $manager->filter($last_token, $value, $obj_prefix, $obj_path);
+ ($key, $value, my $obj) = $manager->filter($key_token, $value, $obj_prefix, $obj_path, @additional_tokens);
_add_uniq($with_objects, $obj) if $obj;
} else {
_add_uniq($with_objects, $obj_path) if $obj_path;