Transient DS.Model Attributes in EmberJS
In EmberJS, by default model properties are always saved through the serializers. This can be a problem if you have an Object in your model that is not a DS.Model, and you may get TypeError: cyclic object value errors in JSON.stringify when trying to serialize the model back to LocalStorage.
By extending the JSONSerializer (or the RESTSerializer in the same way), you can provide a new property transient
to your model properties that will not persist this property when the object is saved:
DS.JSONSerializer.reopen({
serializeAttribute: function(record, json, key, attribute) {
if (!attribute.options.transient) {
return this._super(record, json, key, attribute);
}
}
});
App.User = DS.Model.create({
admin: DS.attr('boolean', { transient: true })
})