JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Pagination, sorting and filtering of related resources no longer work properly

Open
#1,117 1 comment 4 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

After upgrading to 0.9.0, when records for a relationship is overridden in the resource, pagination, sorting and filtering no longer works. Example, we have a UserResource and it has a has_many :comments relationship and on the resource, we override the method like:

def records_for_comments(_options = {})
  # do some custom stuff here
end

After debugging, I can see that this is because from the older versions, in RelationshipBuilder, the logic where the records are sorted, filtered and paginated in the block:

define_on_resource relationship_name do |options = {}|
  # . . .
end

are moved to this block:

define_on_resource associated_records_method_name do |options = {}|
  # . . .
end

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 in RelationshipBuilder and compare the relationship_name and associated_records_method_name define_on_resource blocks. Trace records_for_comments for an overridden relationship, then verify that sorting, filtering, and pagination still apply when the custom method is used. The issue does not mention a test file, so identify the relevant relationship behavior tests before making the change.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.