serializePolymorphicType (snapshot, json, relationship)
You can use this method to customize how polymorphic objects are serialized. Objects are considered to be polymorphic if { polymorphic: true }
is pass as the second argument to the DS.belongsTo
function.
Example
app/serializers/comment.js
import DS from 'ember-data'; export default DS.JSONSerializer.extend({ serializePolymorphicType: function(snapshot, json, relationship) { var key = relationship.key, belongsTo = snapshot.belongsTo(key); key = this.keyForAttribute ? this.keyForAttribute(key, "serialize") : key; if (Ember.isNone(belongsTo)) { json[key + "_type"] = null; } else { json[key + "_type"] = belongsTo.modelName; } } });
Parameters:
-
snapshot
DS.Snapshot
-
json
Object
-
relationship
Object
Please login to continue.