Skip to content

Commit

Permalink
Update destroy blueprint action so that afterDestroy lifecycle call…
Browse files Browse the repository at this point in the history
…backs will still run by default
  • Loading branch information
rachaelshaw committed Aug 24, 2019
1 parent eea8df4 commit ba450bf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/hooks/blueprints/actions/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ module.exports = function destroyOneRecord (req, res) {

// (Note: this could be achieved in a single query, but a separate `findOne`
// is used first to provide a better experience for front-end developers
// integrating with the blueprint API out of the box. If we didn't need
// or care about that, we could just use `.meta({fetch: true})` when calling
// `.destroy()`.
Model.destroy(_.cloneDeep(criteria)).exec(function destroyedRecord (err) {
// integrating with the blueprint API out of the box. However, we'll also include
// the meta query optons for the purpose of enabling the `afterDestroy`
// lifecycle callback (which only runs if `.meta({fetch: true})` is included).
Model.destroy(_.cloneDeep(criteria)).meta(queryOptions.meta)
.exec(function destroyedRecord (err) {
if (err) {
switch (err.name) {
case 'UsageError': return res.badRequest(formatUsageError(err, req));
Expand Down

0 comments on commit ba450bf

Please sign in to comment.