DS.RESTSerializer#serialize()

serialize (snapshot, options) Object Inherited from DS.JSONSerializer but overwritten in addon/serializers/rest.js:508 Called when a record is saved in order to convert the record into JSON. By default, it creates a JSON object with a key for each attribute and belongsTo relationship. For example, consider this model: app/models/comment.js import DS from 'ember-data'; export default DS.Model.extend({ title: DS.attr(), body: DS.attr(), author: DS.belongsTo('user') }); The default se

DS.RESTSerializer#pushPayload()

pushPayload (store, payload) Defined in addon/serializers/rest.js:380 This method allows you to push a payload containing top-level collections of records organized per type. { "posts": [{ "id": "1", "title": "Rails is omakase", "author", "1", "comments": [ "1" ] }], "comments": [{ "id": "1", "body": "FIRST" }], "users": [{ "id": "1", "name": "@d2h" }] } It will first normalize the payload, so you can use this to push in data streaming in from y

DS.RESTSerializer#payloadTypeFromModelName()

payloadTypeFromModelName (modelname) Stringpublic Defined in addon/serializers/rest.js:910 payloadTypeFromModelName can be used to change the mapping for the type in the payload, taken from the model name. Say your API namespaces the type of a model and expects the following payload when you update the post model, which has a polymorphic user relationship: // POST /api/posts/1 { "post": { "id": 1, "user": 1, "userType": "api::v1::administrator" } } By overwriting payloadTyp

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 Hous

DS.RESTSerializer#normalize()

normalize (modelClass, resourceHash, prop) Object Inherited from DS.JSONSerializer but overwritten in addon/serializers/rest.js:91 Normalizes a part of the JSON payload returned by the server. You should override this method, munge the hash and call super if you have generic normalization to do. It takes the type of the record that is being normalized (as a DS.Model class), the property where the hash was originally found, and the hash to normalize. For example, if you have a payload that l

DS.RESTSerializer#modelNameFromPayloadType()

modelNameFromPayloadType (payloadType) Stringpublic Inherited from DS.JSONSerializer but overwritten in addon/serializers/rest.js:861 modelNameFromPayloadType can be used to change the mapping for a DS model name, taken from the value in the payload. Say your API namespaces the type of a model and returns the following payload for the post model, which has a polymorphic user relationship: // GET /api/posts/1 { "post": { "id": 1, "user": 1, "userType: "api::v1::administrator"

DS.RESTSerializer#modelNameFromPayloadKey()

modelNameFromPayloadKey (key) String Inherited from DS.JSONSerializer but overwritten in addon/serializers/rest.js:444 This method is used to convert each JSON root key in the payload into a modelName that it can use to look up the appropriate model for that part of the payload. For example, your server may send a model name that does not correspond with the name of the model in your app. Let's take a look at an example model, and an example payload: app/models/post.js import DS from 'ember

DS.RESTSerializer#keyForPolymorphicType()

keyForPolymorphicType (key, typeClass, method) String Defined in addon/serializers/rest.js:60 keyForPolymorphicType can be used to define a custom key when serializing and deserializing a polymorphic type. By default, the returned key is ${key}Type. Example app/serializers/post.js import DS from 'ember-data'; export default DS.RESTSerializer.extend({ keyForPolymorphicType: function(key, relationship) { var relationshipKey = this.keyForRelationship(key); return 'type-' + rel

DS.RESTSerializer#extractPolymorphicRelationship()

extractPolymorphicRelationship (relationshipType, relationshipHash, relationshipOptions) Object Inherited from DS.JSONSerializer but overwritten in addon/serializers/rest.js:786 You can use this method to customize how a polymorphic relationship should be extracted. Parameters: relationshipType Object relationshipHash Object relationshipOptions Object Returns: Object

DS.RESTSerializer

DS.RESTSerializer Class Extends: DS.JSONSerializer Defined in: addon/serializers/rest.js:16 Module: ember-data Normally, applications will use the RESTSerializer by implementing the normalize method. This allows you to do whatever kind of munging you need, and is especially useful if your server is inconsistent and you need to do munging differently for many different kinds of responses. See the normalize documentation for more information. Across the Board Normalization There are also a n