I have a details: DS.attr('recursive_object')
custom transformation (it's a recursive object).
The details
attr can be edited in place, without the actual object reference changing (e.g., a sub-detail on the details attr is edited). This, however, doesn't trigger the parent record's isDirty
flag.
How can I manually notify a DS.Model record that it's been updated?
Model definition:
App.MyRecord = DS.Model.extend
details: DS.attr "recursive object"
Editing details
# record is an instance of App.MyRecord
# makes a change to the record's details attr
record.makeChangeToDetails()
record.get('isDirty') # still false because Ember doesn't know that a sub-detail changed.
Things I've tried:
Wrapping record.makeChangeToDetails()
with will/didSetProperty
calls:
record.send 'willSetProperty', name: 'details'
record.makeChangeToDetails()
record.send 'didSetProperty', name: 'details'
Calling notifyPropertyChange
record.notifyPropertyChange 'details'
Calling set
and passing it the same object
record.makeChangeToDetails()
record.set 'details', record.get('details')
I've also tried sending various other DS.model states events from here: https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/model/states.js
including didChangeData
, becameDirty
but none of these worked.
Any ideas?
I got some clues from this other question: How to manually set an object state to clean (saved) using ember-data
In particular, the bit about:
record.get('stateManager').transitionTo('loaded.saved')
Using 1.0.0-beta.7+canary.b45e23ba
, this appears to do the job:
> record.isDirty()
< false
> record.send('becomeDirty')
< undefined
> record.isDirty()
< true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With