I’ve been Googling for a while now, but haven’t found any good solution.
The root of the problem is that my records aren’t being set to isDirty when using this method:
DS.JSONTransforms.object = {
deserialize: function(serialized) {
return Ember.isNone(serialized) ? {} : serialized;
},
serialize: function(deserialized) {
return Ember.isNone(deserialized) ? {} : deserialized;
}
}
From what I gather this is an old method that apparently still works, since it handles the JSON objects I’m throwing at it, but it’s not setting my records to isDirty when making edits.
What you now should be using is registerTransform on your adapter (according to this https://github.com/emberjs/data/issues/517). But my custom transform isn’t being registered, so I guess I’m putting it at the wrong place (same place as my previous JSONTransforms).
DS.RESTAdapter.registerTransform('object', {
deserialize: function(serialized) {
return Em.none(serialized) ? {} : serialized;
},
serialize: function(deserialized) {
return Em.none(deserialized) ? {} : deserialized;
}
});
Any one have knowledge to share about this?
The issue with
isDirtyis not because you’re not usingregisterTransform, the behavior will be the same.For now, Ember Data does not support object attributes, one of the difficulty is in fact to observe the changes to set the
isDirtyflag.There is an open issue for this that you can track on github.
A workaround would be to declare the nested objects as proper
DS.Modeland set an embedded relationship between them.For the example, let’s say you have a date object sended with a post :
You will declare the model as following :
And add a mapping in your adapter :
See this answer for more detail about the embedded mapping option.