ember-model icon indicating copy to clipboard operation
ember-model copied to clipboard

Add attribute level save/update control

Open ahacking opened this issue 11 years ago • 0 comments

This PR add the ability to control what attributes or relationships are sent back to the server as sometimes is it is undesirable to send everything back, e.g. read-only attributes or other meta data managed by the server or relationships which should not be managed through the model.

On your model you can now do:

var Person = Model.extend({
   createdAt: Ember.attr(Date, {update: false}),
   searchHits: Ember.attr(Number, {save: false}),
   friendships: Ember.hasMany('App.Friendship', {save: false})
});

The save: false option prevents the attribute ever being sent on a create or update, whilst the update: false option will never update the attribute, but does allow the value to be sent on a create. This control is intended to be independent/orthogonal of any adapter implementation since it controls the toJSON() serialisation of the model which occurs prior to the data being given to the adapter for persistence.

ahacking avatar May 26 '14 01:05 ahacking