Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use modelNameFromPayloadKey when type is given #4194

Merged

Conversation

backspace
Copy link
Contributor

The code checked for a model using the possibly-overridden modelNameFromPayloadKey but didn’t use the override when getting the serialiser and model.

The test is really only verifying the store.modelFor(this.modelNameFromPayloadKey(hash.type)); change, not the serialiser one, since I didn’t see any tests for custom serialisers in this file. Let me know if I should make a test for that regardless.

@pangratz
Copy link
Member

pangratz commented Mar 6, 2016

I think it would be good to add a test for the correct serializer too. This is an example of using a custom serializer in the tests.

Also, I think this is a bugfix. Can you prefix the commit with [BUGFIX beta] so this is included in the next beta release?

};

var jsonHash = {
"home-planets": [{ id: "1", name: "Umber", type: "home-planets" }]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of changing type: "home-planets" to type: "my-custom-type" to make it more clear that modelNameFromPayloadKey is used to resolve the model and serializer?

@backspace backspace force-pushed the modelNameFromPayloadKey-with-type branch from aca7096 to 3d89ecd Compare March 6, 2016 23:03
@backspace
Copy link
Contributor Author

Thanks for the pointer to an example serialiser override. I’ve overwritten the commit with a similar assertion for that and added the [BUGFIX beta] prefix to the commit message. Let me know if anything else is necessary!

serializer = store.serializerFor(hash.type);
modelClass = store.modelFor(hash.type);
serializer = store.serializerFor(this.modelNameFromPayloadKey(hash.type));
modelClass = store.modelFor(this.modelNameFromPayloadKey(hash.type));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized this now, but at a first glance it looks weird the the modelName is normalized by a function called modelNameFromPayloadKey; since the passed argument is technically not a key from the payload.

That function originally has been added for the case where the payload key is different. So the blog/post entry in the following payload is used for the post model (see this documentation):

{
  "blog/post": {
    "id": 1
  }
}

modelNameFromPayloadKey is however already used within json serializer to normalize the modelName from hash.type (see here); so this would not be the first time here that this function is used differently than the name would imply.


To be clear, I think it is definitely a bugfix to use the normalized modelName within the if branch here, so this PR looks good to me. I am just not sure if there should be a different function (like modelNameFromPayloadType or something), which would be more appropriate...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yes, I see the confusion. The API that led me to find this bug is a weird pseudo-JSON API that was settled during the RC phase, it uses type. I was confused while debugging by the role that JSONSerializer inheritance played, but you probably know better than me whether it’s feasible to change the method name.

@backspace
Copy link
Contributor Author

I see that this has conflicts now. Is it worth rebasing to keep updated? Might it eventually be merged?

@pangratz
Copy link
Member

So this has been discussed in the team meeting. Eventually the inconsistency should be addressed via new additional modelNameFromPayloadType and payloadTypeFromModelName hooks, but they are out of scope for this PR.

@backspace can you rebase this PR and fix the merge conflicts? After that, this is good to go 🚀

The code checked for a model using the possibly-overridden
modelNameFromPayloadKey but didn’t use the override when
getting the serialiser and model.
@backspace backspace force-pushed the modelNameFromPayloadKey-with-type branch from 3d89ecd to 0f46f66 Compare March 19, 2016 13:12
@backspace
Copy link
Contributor Author

Thanks for the update on the inconsistency.

Rebased and ready! 😀

pangratz added a commit that referenced this pull request Mar 19, 2016
…type

Use modelNameFromPayloadKey when type is given
@pangratz pangratz merged commit 762139e into emberjs:master Mar 19, 2016
@pangratz
Copy link
Member

🎉 👯 thanks @backspace!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants