Skip to content

Instantly share code, notes, and snippets.

@csprocket777
Last active August 29, 2015 13:57
Show Gist options
  • Save csprocket777/9916933 to your computer and use it in GitHub Desktop.
Save csprocket777/9916933 to your computer and use it in GitHub Desktop.
Ember-Data belongsTo / hasMany isDirty workaround. NOTE: These are used in an Ember-App-Kit application setup.
export default DS.Model.extend({
modelIsDirty: DS.attr('boolean', {default: false}),
relationshipWatchList: [],
relationshipWatcherSetup: function(){
this.get('relationshipWatchList').forEach(function(item,index,enumerable){
this.addObserver(item, this, "changeObserver");
}, this);
}.on('init'),
changeObserver: function(){
if( this.get('isDeleted') === false )
{
var isDirty = this.get('relationshipWatchList').any(function(item,index,enumerable){
return this.get(item) !== this.get('_data')[item];
}, this);
this.set('modelIsDirty', isDirty );
}
}
});
import BaseModel from "appkit/models/base-model";
export default BaseModel.extend({
prop1: DS.belongsTo('option'),
prop2: DS.belongsTo('option'),
prop3: DS.belongsTo('option'),
relationshipWatchList: ['prop1', 'prop2', 'prop3']
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment