DS.RESTSerializer#payloadKeyFromModelName()

payloadKeyFromModelName (modelName) String

Defined in addon/serializers/rest.js:693

You can use payloadKeyFromModelName to override the root key for an outgoing request. By default, the RESTSerializer returns a camelized version of the model's name.

For a model called TacoParty, its modelName would be the string taco-party. The RESTSerializer will send it to the server with tacoParty as the root key in the JSON payload:

{
  "tacoParty": {
    "id": "1",
    "location": "Matthew Beale's House"
  }
}

For example, your server may expect dasherized root objects:

app/serializers/application.js
import DS from 'ember-data';

export default DS.RESTSerializer.extend({
  payloadKeyFromModelName: function(modelName) {
    return Ember.String.dasherize(modelName);
  }
});

Given a TacoParty model, calling save on it would produce an outgoing request like:

{
  "taco-party": {
    "id": "1",
    "location": "Matthew Beale's House"
  }
}

Parameters:

modelName String

Returns:

String
doc_EmberJs
2016-11-30 16:50:36
Comments
Leave a Comment

Please login to continue.