How to manipulate record state manually?


Hi all, I am working for a project which use websock and embed-data to fetch data from server.

In some cases, I fetch data changes via websock from server and update the record, like code followed:

whenDataChanges: (data) ->
    @store.find("comment", ->
        comment.set('text', data.text)

When i set property of comment record manually, it’s state become dirty, which make the problem. Because the record comes from the server, I don’t want to call .save() method to remove the state(my request payload is huge).

I searched STO and the forum, found some topics about it:

but them don’t work for my case. How can i remove the dirty state? Thank you all.


I think you could try the push method of DS.Store. This way you your model won’t get dirty.

For example in your case

var controller = this;
// in the success part of your promise:'comment', { id:, text: data.text });


Maybe you could manually set the state:

comment.set('currentState', DS.RootState.loaded.saved);

You can have a look at the DS.RootState object here

Best Regards, toovy


If you were doing this to set one property of many, would the exclusion of the other properties have any effect?


If I exclusion the others properties, they will became empty or zero.


push has a third parameter: _partial

I guess if you pass true, the other properties won’t be affected.'comment', { id:, text: data.text }, true);


Wow, the parameter does the work. Thank you @splattne!

Also thank @toovy, Your code works too, but I prefer to use push method.