JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Filter on relationship route?
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Description
Is it possible to filter on a relationship route?
class PostResource < JSONAPI::Resource
has_many :comments
def records_for_comments(options = {})
records_for(:comments).public
end
end
class CommentResource < JSONAPI::Resource
has_one :post
filter :active,
apply: -> (records, value, options) {
if value
records.active
else
records.inactive
end
}
end
This calls the filter:
/comments?filter[active]=1
This does not seem to call the filter:
/posts/14/comments?filter[active]=1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PostResource records_for_comments method and compare filter handling for /comments?filter[active]=1 versus /posts/14/comments?filter[active]=1. Trace the nested relationship route entry point and confirm whether the CommentResource active filter is applied there; done means the nested route produces the same filtering behavior as the direct comments route.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100