So I have this model that gets populated via .fetch()
my problem is. It will either always PUT, or always POST but never is .save()
acting "smart".
The model is populated from a fetch, which if anything is returned from the fetch, its ever at most a single item, so running a collection for it is a bit abusive. Anyway.. I know that the my issue is in part related to my use of idAttribute
if I use it, the .save()
always does a PUT if I don't its always a POST.
my.Models.note = Backbone.Model.extend({
idAttribute:'note',
initialize: function (data) {
this.user_id = data.user_id;
},
parse: function(response) {
if (response.status == 'SUCCESS') {
return response.data;
}
},
url:function(data)
{
var url = '/notes/';
url += '?user_id='+this.user_id;
return url;
}
});
Its depends on your data , you should have id attribute in your data fetched from server, when you call save then automatically it sends a PUT call.if id is null then it send a POST call