Pluralizing the body of POST requests

I have a DS.Model called “myModel” and when I am trying to add a new record to item I am doing the following:

//in controller
this.store.createRecord('myModel', {name: 'myModelName'}).save();

The request that goes out is:

POST
http://<url>/myModels

which is correct – it pluralized the model by using “/myModels” instead of “myModel”.

However, the body of the POST is:

{myModel: {name: "myModelName"}}

and that’s where I need a modification. The server is expecting:

{myModels: {name: "myModelName"}}

What do I need to do pluralize the body of the POST message? I’ve looked at overriding “pathForType” in DS.RESTAdapter, but after tweaking with it, I am pretty certain that “pathForType” only modifies the URL (which is already correct), but not the body.

I feel like I need to override some other function, but I can’t seem to find which one. Could someone please advise? Thank you.

On Jul 27, 2015, at 10:13 AM, xwingz noreply@emberjs.com wrote:

What do I need to do pluralize the body of the POST message? I’ve looked at overriding “pathForType” in DS.RESTAdapter, but after tweaking with it, I am pretty certain that “pathForType” only modifies the URL (which is already correct), but not the body.

Correct.

I feel like I need to override some other function, but I can’t seem to find which one. Could someone please advise? Thank you.

I think you may need to set an application-level serializer, which extends whichever serializer you’re currently using, and overrides the serializeIntoHash method.

You don’t say which serializer you’re using, but JSON is a good guess :wink:

http://emberjs.com/api/data/classes/DS.JSONSerializer.html#method_serializeIntoHash

1 Like

Thanks scribe, that worked beautifully.