serializeBelongsTo (snapshot, json, relationship)
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
Please login to continue.