JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Filtering included resources

Open
#314 4 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

We have a use-case where it would be useful to apply filters to the included resources.

Dummy example:

class UserResource < JSONAPI::Resource
  has_many :socks
  has_many :shoes
end
class SockResource < JSONAPI::Resource
  has_one :user
  filter :in_use
end
class ShoeResource < JSONAPI::Resource
  has_one :user
  filter :in_use
end

Individually, one can filter the shoes and socks
/shoes?filter[in_use]=true
/socks?filter[in_use]=true

I was wondering if it would be possible to filter the shoes and socks when included with the User?

e.g. To get the user, and the shoes and socks he currently has in use, something like:

/users/1?include=shoes,socks&filter[shoes][in_use]=true&filter[socks][in_use]=true

Is this in the scope of jsonapi-resources? or would it be best to find a custom approach?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the UserResource, SockResource, and ShoeResource examples and verify how the shown include and filter query parameters are currently interpreted. Determine whether filtering included resources is supported; done means a documented supported behavior with coverage, or a clear conclusion that a custom approach is required.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.