Reputation: 8507
I am working with an OData compliant back end which expects a certain json structure.
To change the default POST request data that your ember model is serialized into you can create your own serializer on a per model basis. I have a question model with a text attribute.
serializer
Excelsior.QuestionSerializer = DS.RESTSerializer.extend({
serialize: (question, options) ->
json = {
text: "lalalala"
}
output
{question: {text: "lalalala"}}
what I would like
{d: {text: "lalala"}}
Upvotes: 1
Views: 277
Reputation: 1947
The adapter is what's namespacing the data, so if you override the relevant methods in your adapter, you can change that functionality:
createRecord: function(store, type, record) {
var url = this.buildURL(type.typeKey);
var data = store.serializerFor(type.typeKey).serialize(record);
return this.ajax(url, "POST", { data: data });
},
updateRecord: function(store, type, record) {
var data = store.serializerFor(type.typeKey).serialize(record);
var id = get(record, 'id'); //todo find pk (not always id)
return this.ajax(this.buildURL(type.typeKey, id), "PUT", { data: data });
},
Upvotes: 1