DS#save
DS#save(resourceName, id[, options])
The "U" in "CRUD". Persist an item already in the data store in its current state through whichever adapter is being used and inject the result into the data store.
Returns a promise.
Arguments
name | type | description |
---|---|---|
resourceName | string | The name of the resource to use. Unnecessary if using the resource directly. |
id | string or number | The primary key of the item to save. |
options | object | Configuration options. Also passed through to the adapter and (conditionally) to DS.inject . |
options.adapter | string | Override the default adapter. |
options.cacheResponse | boolean | Inject the result into the store. Default: true . |
options.changesOnly | boolean | Only send changed and added values to the adapter. Default: false . |
options.always | array | Property names which are always sent, even when not changed. Only relevant when changesOnly is true . |
options.beforeValidate | function | Override the default beforeValidate hook. |
options.validate | function | Override the default validate hook. |
options.afterValidate | function | Override the default afterValidate hook. |
options.beforeUpdate | function | Override the default beforeUpdate hook. |
options.afterUpdate | function | Override the default afterUpdate hook. |
Examples
Document.find(5).then(function (document) {
document.name; // 'John'
document.name = 'Johnny';
// See the Method Variants section below for different ways to call DS#save
return Document.save(5);
}).then(function (document) {
document.name; // 'Johnny'
});
Method Variants
You can call DS#save in multiple ways:
- DS#save(resourceName, id);
- Resource#save(id); // where Resource was created by DS#defineResource
- Instance#DSSave(); // where instance is an instance of a Resource
Need help?
Want more examples or have a question? Ask on the Slack channel or post on the mailing list then we'll get your question answered and probably update this wiki.
Updated less than a minute ago