ember-data-change-tracker
Version:
Track changes and rollback object attributes and relationships. Ember data 2.5+
26 lines (22 loc) • 724 B
JavaScript
import Ember from 'ember';
// EmberData does not serialize hasMany relationships by default
export default Ember.Mixin.create({
keepValue(record, key) {
return record.get('isNew') || record.didChange(key);
},
serializeAttribute: function(snapshot, json, key) {
if (this.keepValue(snapshot.record, key)) {
return this._super(...arguments);
}
},
serializeBelongsTo: function(snapshot, json, relationship) {
if (this.keepValue(snapshot.record, relationship.key)) {
return this._super(...arguments);
}
},
serializeHasMany: function(snapshot, json, relationship) {
if (this.keepValue(snapshot.record, relationship.key)) {
return this._super(...arguments);
}
}
});