JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
has_one foreign_key_on: :related fails on save
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Description
When saving a resource with a has_one relationship with foreign_key_on: :related I get an error of undefined method 'foreign_key=' for the model. I'm not sure if the intent is to change the relationship on the related items when save or not. For now I did the following patch to not update any relationships that have foreign_key_on: :related
def replace_to_one_link(relationship_type, relationship_key_value)
if(self.class._relationships[relationship_type.to_sym]).belongs_to?
super
end
end
def replace_polymorphic_to_one_link(relationship_type, relationship_key_value, relationship_key_type)
if(self.class._relationships[relationship_type.to_sym]).belongs_to?
super
end
end
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 save failure for a has_one relationship using foreign_key_on: :related, then trace the relationship save path through replace_to_one_link and replace_polymorphic_to_one_link. Determine the intended behavior for related-item relationships and add or update coverage for the failing case; done means saving no longer calls an unavailable foreign_key= method and the intended relationship behavior is verified.
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
- 28/100