destroy
Delete an instance from the service via the connection.
instance.destroy(success, error)
Calls destroy for the instance
.
Parameters
Returns
{Promise<Instance>}
:
a promise that resolves to the instance if successful
Usage
// import connection plugins
var canMap = require("can-connect/can/map/map");
var constructor = require("can-connect/constructor/constructor");
var dataUrl = require("can-connect/data/url/url");
// define connection types
var Todo = DefineMap.extend({
id: "number",
complete: "boolean",
name: "string"
});
// create connection
connect([canMap, constructor, dataUrl],{
Map: Todo,
url: "/todos"
})
// read instance
Todo.get({id: 5}).then(function(todo){
if (todo.complete) {
// delete instance
todo.destroy();
}
});