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

match() fails with JSONAPI for relationship when serializer's payloadKeyFromModelName() doesn't pluralize #213

Closed
cristinawithout opened this issue Jun 29, 2016 · 2 comments

Comments

@cristinawithout
Copy link
Contributor

Our application serializer has the following method that purposely does not pluralize.

payloadKeyFromModelName(modelName) { return Ember.String.underscore(modelName); }

mock-create-request.js is setting serializeMode to true and jsonapi-fixture-converter.js uses that to pluralize the type.

So when I try to use mockCreate().match() with a relationship, the type key is getting pluralized in the expected data and the match fails because our serializer does not pluralize the type key.

Example:
mockCreate('entry-type').match({name: 'My Name', handle: 'my_name', section: {id: '1', type: 'section'}})

And when it reaches this comparison, the data is:

expectedData.data:

{
attributes: {
    handle: "my_name",
    name: "My Name"
},
relationships: {
    section: {
        data: {
            id: "1",
            type: "sections" // pluralized
        }
    }
},
type: "entry-types" // pluralized
}

requestData.data:

{
attributes: {
    handle: "my_name",
    name: "My Name"
},
relationships: {
    section: {
        data: {
            id: "1",
            type: "section" // not pluralized
        }
    }
},
type: "entry-type" // not pluralized
}

So the match fails, but the requestData is exactly as it should be using our serializer.

Is it possible to instead lookup serializers by modelName and use payloadKeyFromModelName() as the JSONAPI serializer does when serializing the type?

@danielspaniel
Copy link
Collaborator

@cristinawithout .. good point here.
Do you think you could put together a PR that would handle this ??
and put a nice test together ( which would be pretty similar to what you have above ) ??

@danielspaniel
Copy link
Collaborator

v2.7.0-beta.8 has your changes

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

No branches or pull requests

2 participants