Ember Data: how to set isDirty for recording?

I have a custom conversion details: DS.attr('recursive_object') (this is a recursive object).

details attr can be edited in-place without changing the actual object reference (for example, detailed information about attr elements has been edited). This, however, does not call the flag of the parent record isDirty .

How can I manually notify an updated DS.Model entry?

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 details attr record.makeChangeToDetails() record.get('isDirty') # still false because Ember doesn't know that a sub-detail changed. 

What I tried:

Wrap record.makeChangeToDetails() with calls to will/didSetProperty :

 record.send 'willSetProperty', name: 'details' record.makeChangeToDetails() record.send 'didSetProperty', name: 'details' 

Call notifyPropertyChange

 record.notifyPropertyChange 'details' 

Call set and pass the same object to it.

 record.makeChangeToDetails() record.set 'details', record.get('details') 

I also tried sending other DS.model state events from here: https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/model/states.js including didChangeData , becameDirty , but neither one of them did not work.

Any ideas?

+6
source share
2 answers

I have some tips from this other question: How to manually set the state of an object for cleaning (saving) using ember data

In particular, a bit about:

record.get('stateManager').transitionTo('loaded.saved')

+3
source

Using 1.0.0-beta.7+canary.b45e23ba , this seems to do the job:

 > record.isDirty() < false > record.send('becomeDirty') < undefined > record.isDirty() < true 
+3
source

All Articles