I have a model which id is a code that must be written by the user and this code will be the primary key on the DB.
So, to create a new register I need to write the code but when i call the save() method I’m expecting one POST, but because de idAttribute has an value, I get always one PUT.
This is my model very simplified
Course = Backbone.Model.extend({
idAttribute: "courseCode"
});
As Jack commented, you should be using id, not idAttribute. (Unless we’ve misunderstood, and
courseCodeis the name of the primary key on the server; in that case, carry on.)Whether the model is persisted using
POSTorPUTwhen you call save() depends on the isNew() function. The default implementation compares id to null to determine if the model has been saved yet or not. You will need to implement your own isNew function to determine whether to create or update your record. For example, you could try something like this: