Autosave with JSON fields


#1

I have a model (using Ember Data) that I would like to autosave whenever any of the fields change. I have been using this autosave plugin and it works great, except that I have JSON fields that do not trigger the autosave.

My model has fields that look like this:

title: DS.attr('string'),
options: DS.attr()

Whenever the title attribute changes, it will trigger the setUnknownProperty method on the ObjectProxy used by the ember-autosave plugin. However, if I change, for example, options.layout, setUnknownProperty does not get called, so it won’t trigger the autosave.

One alternative I tried was to set observers on all the properties in the options object. However, once I save the model to the database, Ember gets data back from the server and reloads the model, which then fires the observers again, resulting in another save, causing an infinite loop.

What options do I have here? Is there a way to register JSON fields/properties as regular fields on the model?