Fix polymorphic type setter#882
Merged
barelyknown merged 2 commits intoJSONAPI-Resources:masterfrom Oct 24, 2016
Merged
Conversation
Collaborator
|
Nice catch. Can you add a test that fails without this fix and passes with it? |
Contributor
Author
|
@barelyknown I added a test. I'm not familiar with the rails test framework (I used to use rspec) so feedback is welcome. |
Collaborator
|
Nice and simple - thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey @lgebhardt!
We encounter a problem associated with the polymorphic relation. Here is an example in code:
Setup
Models:
Resources:
Usage
Request: [ POST ]
/topics{ "data": { "attributes": { "name": "Topic name", }, "relationships": { "document": { "data": { "type": "templates", "id": "1" } }, }, "type": "topics" } }Problem
Newly created topic has the wrong name of
document_typefiled.After typing
topic.document_typeit wasTemplatesbut in fact, the polymorphic type should be taken from a model name and it should look likeAccount::Templatebecause it's the real name of the resource's model's class name.Solution
I overwrite a method which assigns polymorphic type, and I created a method which looking for a real model class name of given relation's
key_type.I hope it will help :)