jsonapi-resources: Filter apply never being called

I have a filter named tags, which looks like this:

filter :tags,
       verify: ->(values, _context) { values.flatten },
       apply: ->(records, values, _options) { raise("FOO BAR BAZ"); records.joins(:tags).where(tags: values)  }

Notice the raise in apply? That doesn’t ever get called…

However, if I throw that, or binding.pry into a different filter, it does get called. Is there something special with the word tags that I’m missing?

Update:

With request params of

Parameters: {"filter"=>{"tags"=>["63"], "status"=>["not_started"], "account_groups"=>["1"]}, "include"=>"account-group,tags", "page"=>{"size"=>"10"}, "sort"=>"last-name"}

and tapping into self.apply_filter, I’m seeing the tag filter coming through named tags.id, whereas other filters named as I’d expect (the param name, which correlates to the filter name)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21 (8 by maintainers)

Most upvoted comments

I currently have the same issue on 0.9, the problem appears if I want to define a custom filter for a relationship that is defined.

has_one :branch and then filter :branch with custom code <- this is never called

Confirmed I am able to replicate this issue when an association is the same name as the filter.

@outsmartin I tried to create with random name like “blablabla” and it’s never called too. The name of the filter is ALWAYS interpreted as some column of the model and throw an error column blablabla doesn't exist