+sub _dispatch_custom_filters {
+ my ($class, $with_objects, $key, $value) = @_;
+
+ # the key should by now have no filters left
+ # if it has, catch it here:
+ die 'unrecognized filters' if $key =~ /:/;
+
+ my @tokens = split /\./, $key;
+ my $last_token = pop @tokens;
+ my $curr_class = $class->object_class;
+
+ for my $token (@tokens) {
+ eval {
+ $curr_class = $curr_class->meta->relationship($token)->class;
+ 1;
+ } or do {
+ require Carp;
+ Carp::croak("Could not resolve the relationship '$token' in '$key' while building the filter request");
+ }
+ }
+
+ my $manager = $curr_class->meta->convention_manager->auto_manager_class_name;
+ my $obj_path = join '.', @tokens;
+ my $obj_prefix = join '.', @tokens, '';
+
+ if ($manager->can('filter')) {
+ ($key, $value, my $obj) = $manager->filter($last_token, $value, $obj_prefix);
+ _add_uniq($with_objects, $obj) if $obj;
+ } else {
+ _add_uniq($with_objects, $obj_path) if $obj_path;
+ }
+
+ return ($key, $value);
+}
+
+sub _add_uniq {
+ my ($array, $what) = @_;
+
+ $array //= [];
+ @$array = (uniq @$array, listify($what));
+}
+