JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Included resource choosing wrong Arel table

Open
#1,127 6 comments 1 reaction 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'm running into an issue where including one resource (user) ends up using another Arel table (account), and thus the include blows up with Internal Server Error: key not found: 11. 11 is the Account ID of the user, but the user ID is 68, which is specified on the parent resource as user_id.

I've stepped through the code a bit to determine that pluck_attrs in JSONAPI::Resource#preload_include_fragments has the wrong Arel::Table but I'm not sure what the cause of that is.

My models and resources are configured in a very straightforward manner:

JobApplication < ApplicationRecord
  belongs_to :user, inverse_of: :job_applications, touch: true, counter_cache: true
end

User < ApplicationRecord
  has_many :job_applications, inverse_of: :user, dependent: :destroy
end

Any idea why this would be happening?

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 JSONAPI::Resource#preload_include_fragments and inspect how pluck_attrs selects its Arel::Table during the described JobApplication/User include. Reproduce the issue with the association configuration in the report, then verify that including user uses user_id 68 rather than the Account ID 11 and no longer raises the key-not-found error.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.