Last active
August 29, 2015 13:57
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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