0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Reverted destroy function of CRUD plugin to chained promises

refs https://github.com/TryGhost/Team/issues/808

- see referenced issue for context, but turning this function into
  async-await seems to have broken error handling when deleting things
  that don't exist
- i'm really not sure why - but my running theory is that it's something
  to do with Bluebird Promises vs native Promises
- this should keep the same functionality until I can investigate what
  is going on
This commit is contained in:
Daniel Lockyer 2021-06-24 10:17:40 +01:00
parent 323074f106
commit ce68b2e4a9
No known key found for this signature in database
GPG key ID: D21186F0B47295AD

View file

@ -198,7 +198,7 @@ module.exports = function (Bookshelf) {
* @param {Object} [unfilteredOptions]
* @return {Promise<Bookshelf['Model']>} Empty Model
*/
destroy: async function destroy(unfilteredOptions) {
destroy: function destroy(unfilteredOptions) {
const options = this.filterOptions(unfilteredOptions, 'destroy');
if (!options.destroyBy) {
@ -208,8 +208,11 @@ module.exports = function (Bookshelf) {
}
// Fetch the object before destroying it, so that the changed data is available to events
const obj = await this.forge(options.destroyBy).fetch(options);
return obj.destroy(options);
return this.forge(options.destroyBy)
.fetch(options)
.then(function then(obj) {
return obj.destroy(options);
});
},
// When loading an instance, subclasses can specify default to fetch