DS.JSONSerializer#serializeBelongsTo()

serializeBelongsTo (snapshot, json, relationship)

Defined in addon/serializers/json.js:1153

serializeBelongsTo can be used to customize how DS.belongsTo properties are serialized.

Example

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

export default DS.JSONSerializer.extend({
  serializeBelongsTo: function(snapshot, json, relationship) {
    var key = relationship.key;

    var belongsTo = snapshot.belongsTo(key);

    key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo", "serialize") : key;

    json[key] = Ember.isNone(belongsTo) ? belongsTo : belongsTo.record.toJSON();
  }
});

Parameters:

snapshot DS.Snapshot
json Object
relationship Object
doc_EmberJs
2016-11-30 16:49:58
Comments
Leave a Comment

Please login to continue.