Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created November 15, 2011 00:59
Show Gist options
  • Save boxxxie/1365761 to your computer and use it in GitHub Desktop.
Save boxxxie/1365761 to your computer and use it in GitHub Desktop.
Why doesn't my destroy function work with data:{rev....}?
var couchDoc = Backbone.Model.extend(
{
idAttribute: "_id",
save:function(attrs,options){
function updateRev(model,resp,status){
model.set({_rev:status.rev,_id:status.id},{silent: true});
};
options || (options = {});
var model = this;
var success = options.success;
options.success = function(resp, status, xhr){
updateRev(model,resp,status);
if (success){success(model, resp, status);}
};
Backbone.Model.prototype.save.call(this, attrs, options);
},
//DELETE /somedatabase/some_doc?rev=1582603387 HTTP/1.0
destroy:function(options){
options || (options = {});
var model = this;
//_.extend(options,{data:{rev:model.get('_rev')}}); DOESN'T WORK
_.extend(options,{url: model.url()+"?rev="+model.get('_rev')});
Backbone.Model.prototype.destroy.call(this, options);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment