I'm attempting to save only changed attributes of my model by doing the following:
this.model.set("likes", this.model.get("likes") + 1);
this.model.save();
and extending the Backbone prototype like so:
var backbone_common_extension = {
sync: function(method,model,options) {
options.contentType = 'application/json';
if (method == 'update') {
options.data = JSON.stringify(model.changedAttributes() || {});
}
console.log(options.data);
Backbone.sync.call(this, method, model, options);
}
};
_.extend(Backbone.Model.prototype, backbone_common_extension);
The problem is that model.changedAttributes() is always empty. I've tried passing {silent: true} on the set method, but same thing. How can I keep backbone from clearing out changedAttributes() before sync?