Edit Page

.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.

Usage

#
Argument Type Details
1 criteria Dictionary The Waterline criteria to use for matching the record in the database.
Result
#
Type Description
Dictionary? 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.
Errors
#

See Concepts > Models and ORM > Errors for examples of negotiating errors in Sails and Waterline.

Example

#
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`.');
}

Notes

#
  • 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.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

Reference