is there a way to know why a record is in a dirty state in ember data, I mean what are the attributes and relations that has changed.
I'm having isDirty = true after calling a findAll and I want to debug why this happens.
Thanks a lot
Depending on which version of ember-data you're using (and, now, what you're using as an adapter) this could be different. The behavior changed in version 9. Before then, you could say record.isDirtyBecause('belongsTo')
and if the record had been marked dirty because the belongsTo
relationship had changed, it would return true
. Now, due to some shifts in the responsibilities between Stores and Adapters, it's up to the Adapter to handle this.
If you still need this information in your adapter, it will be your responsibility to do any bookkeeping in the
dirtyRecordsForAttributeChange
hook described above.
As of Ember-Data beta 6 or earlier, there is a changedAttributes()
function that returns a hash of the attributes that are changed, and their initial/current values. See http://emberjs.com/guides/models/working-with-records/
For example:
person.changedAttributes(); //=> { isAdmin: [false, true] }
Note that changedAttributes()
is not a property that you can observe; however, if you needed to do so, you could observe all the properties that might change on the model, and then check changedAttributes()
inside your computed property/observes function.
For (contrived) example:
checkAttributes: (->
changed = @get('model').changedAttributes()
if changed['name'] && Object.keys(changed).length == 1
# Do something if name is the only changed attribute
).property('name', 'alias', 'description')