JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

can I do unscoped inside filter

Open
#992 1 comment 0 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

I override self.records methods

def self.records(options = {})
  Course.index_page
end

which return courses that have index flag.

in a filter, I'd like to return all courses that I've purchased.

  filter :paid, apply: ->(records, _value, _options) {
    records.unscoped.where(id:  some_ids)
  }

an error was returned if some_ids includes course that doesn't have index flag.

Internal Server Error: undefined method id' for nil:NilClass /../../gems/jsonapi-resources-ad12cbab49cf/lib/jsonapi/resource_serializer.rb:59:in block in serialize_to_hash'

do I implement it in a wrong way, or some issues here?

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 custom records method and the filter :paid callback, then inspect jsonapi/resource_serializer.rb at line 59. Reproduce the failure with some_ids containing a course without the index flag and determine whether the unscoped result matches the serializer's expectations; done means the behavior is clarified and covered by an appropriate regression test or documented as unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.