.destroyOne()
Destroy the record in your database that matches the given criteria, if it exists.
var destroyedRecord = await Something.destroyOne(criteria);
Before attempting to modify the database, Waterline will check to see if more than one record matches the given criteria. If so, it will throw an error instead of proceeding.
Argument | Type | Details | |
---|---|---|---|
1 | criteria | The Waterline criteria to use for matching the record in the database. |
Type | Description |
---|---|
Since .destroyOne() never destroys more than one record, if a record is destroyed then it is always provided as a result. Otherwise, undefined is returned. |
See Concepts > Models and ORM > Errors for examples of negotiating errors in Sails and Waterline.
var burnedBook = await User.destroyOne({id: 4})
if (burnedBook) {
sails.log('Deleted book with `id: 4`.');
} else {
sails.log('The database does not have a book with `id: 4`.');
}
- Because it always returns the destroyed record, if one was matched, this method does not support .fetch().
- This method can be used with
await
, promise chaining, or traditional Node callbacks.