Override backbone.sync input-only
Is there any possible way to override the sync method for the response PUT
and exclude the field id
from the db and stay the same? I am using the Django REST framework for the API; when trying PUT
, I get:
{"field_errors": "id": ["This field does not exist."],}
I think that if I override the sync and exclude the field id
for PUT
, my problem is resolved, but I don't know how.
+3
source to share
1 answer
Backbone._sync = Backbone.sync;
Backbone.sync = function(method, model, options) {
var params = _.clone(options);
delete model.attributes.id;
params.success = function(model) {
if(options.success) options.success(model);
};
params.error = function(model) {
if(options.error) options.error(model);
};
Backbone._sync(method, model, params);
}
+3
source to share