destroy

  • function
can.Model.destroy  

Destroy a resource on the server.

can.Model.destroy: function(id) -> deferred

If you provide a function, the Model will expect you to do your own AJAX requests.

Parameters

  1. id {*}

    The ID of the resource to destroy.

Returns

{can.Deferred}

A Deferred that resolves to the destroyed model.

can.Model.destroy: "[METHOD] /path/to/resource"

If you provide a URL, the Model will send a request to that URL using the method specified (or DELETE if none is specified) when deleting an instance on the server. (See below for more details.)

Returns

{can.Deferred}

A Deferred that resolves to the destroyed model.

destroy(id) -> Deferred is used by destroy remove a model instance from the server.

Implement with a URL

You can implement destroy with a string like:

Recipe = can.Model.extend({
  destroy : "/recipe/{id}"
},{})

And use destroy to destroy it like:

Recipe.findOne({id: 1}, function(recipe){
     recipe.destroy();
});

This sends a DELETE request to /thing/destroy/1.

If your server does not support DELETE you can override it like:

Recipe = can.Model.extend({
  destroy : "POST /recipe/destroy/{id}"
},{})

Implement with a function

Implement destroy with a function like:

Recipe = can.Model.extend({
  destroy : function(id){
    return $.post("/recipe/destroy/"+id,{});
  }
},{})

Destroy just needs to return a deferred that resolves.