From ba450bff21617d668c77470fc3c979a765936577 Mon Sep 17 00:00:00 2001 From: Rachael Shaw Date: Sat, 24 Aug 2019 16:10:50 -0500 Subject: [PATCH] Update destroy blueprint action so that `afterDestroy` lifecycle callbacks will still run by default --- lib/hooks/blueprints/actions/destroy.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/hooks/blueprints/actions/destroy.js b/lib/hooks/blueprints/actions/destroy.js index 559b7e5bb8..039237b6c0 100644 --- a/lib/hooks/blueprints/actions/destroy.js +++ b/lib/hooks/blueprints/actions/destroy.js @@ -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));