7

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Sherwin Yu
  • 3,180
  • 2
  • 25
  • 41

2 Answers2

3

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')

Community
  • 1
  • 1
lobati
  • 9,284
  • 5
  • 40
  • 61
3

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

> record.isDirty()
< false
> record.send('becomeDirty')
< undefined
> record.isDirty()
< true
aceofspades
  • 7,568
  • 1
  • 35
  • 48