JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Include has_many through: relationship fails
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Description
With the following set of models:
class User < ActiveRecord::Base
...
has_many :participations
has_many :attempts, through: :participations
has_many :completed_attempts, -> { completed }, through: :participations, source: :attempts
...
end
class Participation < ActiveRecord::Base
...
belongs_to :user
has_many :attempts
...
end
class Attempt < ActiveRecord::Base
...
belongs_to :participation
...
end
the request GET /users/1?include=completed-attempts fails. completed-attempts.txt.
Likewise, GET /users/1?include=completed-attempts,attempts fails. completed-attempts_attempts.txt
However, as expected, GET /users/1?include=attempts works. attempts.txt
Changing the order, GET /users/1?include=attempts,completed-attempts, doesn't fail with a 500, however it returns the full list of Attempts for both the attempts and completed-attempts relationships. attempts_completed-attempts.txt
Querying the relations directly from the AR object works correctly for both attempts and completed_attempts.
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
Start by reproducing the listed GET /users/1 requests with the User, Participation, and Attempt model definitions, comparing the include responses with direct ActiveRecord queries. Investigate the handling of filtered has_many-through relationships and nested include order; done means completed-attempts returns only completed attempts and all listed requests avoid a 500.
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