JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Polymorphic association doesn't use model_name
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Description
I have the following (simplified) setup:
class User < ActiveRecord::Base;
class Member < ActiveRecord::Base;
class MemberResource < JSONAPI::Resource
model_name 'User'
end
class BookResource < JSONAPI::Resource
has_one :author, polymorphic: true # type is 'Member' here
end
class AuthorResource < JSONAPI::Resource; end
When I tried to request GET /books/:book_id/author JR will load Member from members table and not users as it's described with model_name.
Would say it's a bug?
I know that my use case is a little bit complex, but in that simplified example we decide to show User as Member in the API (we have different model names).
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 tracing the GET /books/:book_id/author path for BookResource's polymorphic author association and compare its type resolution with MemberResource's model_name 'User'. Reproduce the example with User, Member, MemberResource, and BookResource, then verify that the association resolves to users rather than members while preserving the API resource names.
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
- 38/100