Does anyone know of a way to specify for an Ember model
an attribute which is not persisted?
Basically, we\'re loading some metadata related to each model
When this PR get's merged it will be possible to flag properties as readOnly
. But till then there are some workarounds to this, e.g. overriding your addAttributes
method in the Adapter and deal with your special properties, here an example how this could look like:
Define your Model by adding the new option readOnly
:
App.MyModel = DS.Model.extend({
myMetaProperty: DS.attr('metaProperty', {readOnly: true})
});
and then on the Adapter:
App.Serializer = DS.RESTSerializer.extend({
addAttributes: function(data, record) {
record.eachAttribute(function(name, attribute) {
if (!attribute.options.readOnly) {
this._addAttribute(data, record, name, attribute.type);
}
}, this);
}
});
what this does is to loop over the attributes of your model and when it find's an attribute with the readOnly
flag set it skips the property.
I hope this mechanism works for your use case.