JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Filtering with .where method: no matches without ActiveRecord
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Description
I am really excited about the progress of JSON API spec and the JSON API Resources Gem.
In my experiments with the gem, I found the following to be incompatible with Mongoid, the ActiveRecord replacement for integrating with MongoDB.
def apply_filter(records, filter, value)
records.where(filter => value)
end
The value passed to this method is always an array. In ActiveRecord, passing an array value to the where method builds an IN SQL query. The challenge with something like Mongoid is that values can be stored as arrays. Thus, Contact.where(:github => ['realityendshere']) seems to search for contact records where the github property is exactly equal to the array ['realityendshere'] and does not return the expected results.
It's easy to override this method in my app's resources:
def self.apply_filter(records, filter, value)
records.in(filter => value)
end
Hopefully, this helps anyone else trying to understand how jsonapi-resources gem works with ActiveRecord alternatives.
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
The reported entry point is apply_filter(records, filter, value), which currently calls records.where(filter => value); start there and compare the ActiveRecord and Mongoid behavior described in the issue. Confirm the intended adapter-independent behavior and add coverage for array-valued filters while preserving existing ActiveRecord matching.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, rails, ruby
- Domain
- api, backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100