I would like to unset() the _id attribute from an instance of a model, to make a POST request using the save() model method.
But i get a Uncaught TypeError: Object [object Object] has no method 'call' backbone-min.js because of this line:
myModel.unset('_id');
I am using idAttribute: "_id" so i tried:
myModel.unset('id');
But it doesn’t unset the _id attribute.
Using
model.unset('_id')should work fine. My guess is that the error is thrown by achangeevent listener, either in your code or some library code. In order to not trigger events you can use thesilent:trueoption.However, if you simply want to force the
model.save()method to perform aPOST, you don’t need to unset the_idattribute.Instead override the
model.isNewmethod. Backbone uses this to determine whether a model is new (and should bePOSTed) or existing (and should bePUT). Overriding the method to always return true will make your model to bePOSTed every time: