不要怂,就是干,撸起袖子干!

Commit 36580d98 by Seth Samuel

Return failure from undestroy before hooks execute

1 parent 1c597126
Showing with 4 additions and 10 deletions
...@@ -766,6 +766,8 @@ module.exports = (function() { ...@@ -766,6 +766,8 @@ module.exports = (function() {
* @return {Promise<undefined>} * @return {Promise<undefined>}
*/ */
Instance.prototype.undestroy = function(options) { Instance.prototype.undestroy = function(options) {
if (!this.Model._timestampAttributes.deletedAt) return Promise.reject(new Error("Model is not paranoid"));
options = Utils._.extend({ options = Utils._.extend({
hooks: true, hooks: true,
force: false force: false
...@@ -780,14 +782,8 @@ module.exports = (function() { ...@@ -780,14 +782,8 @@ module.exports = (function() {
return self.Model.runHooks('beforeUndestroy', self, options); return self.Model.runHooks('beforeUndestroy', self, options);
} }
}).then(function() { }).then(function() {
var identifier;
if (!self.Model._timestampAttributes.deletedAt) {
return Promise.reject(new Error("Model is not paranoid"));
} else {
self.dataValues[self.Model._timestampAttributes.deletedAt] = null; self.dataValues[self.Model._timestampAttributes.deletedAt] = null;
return self.save(_.extend(_.clone(options), {hooks : false, omitNull : false})); return self.save(_.extend(_.clone(options), {hooks : false, omitNull : false}));
}
}).tap(function(result) { }).tap(function(result) {
// Run after hook // Run after hook
if (options.hooks) { if (options.hooks) {
......
...@@ -1399,6 +1399,8 @@ module.exports = (function() { ...@@ -1399,6 +1399,8 @@ module.exports = (function() {
* @return {Promise<undefined>} * @return {Promise<undefined>}
*/ */
Model.prototype.undestroy = function(options) { Model.prototype.undestroy = function(options) {
if (!this._timestampAttributes.deletedAt) return Promise.reject(new Error("Model is not paranoid"));
options = Utils._.extend({ options = Utils._.extend({
hooks: true, hooks: true,
individualHooks: false individualHooks: false
...@@ -1429,14 +1431,10 @@ module.exports = (function() { ...@@ -1429,14 +1431,10 @@ module.exports = (function() {
} }
}).then(function() { }).then(function() {
// Run undelete query // Run undelete query
if (!self._timestampAttributes.deletedAt) {
return Promise.reject(new Error("Model is not paranoid"));
} else {
var attrValueHash = {}; var attrValueHash = {};
attrValueHash[self._timestampAttributes.deletedAt] = null; attrValueHash[self._timestampAttributes.deletedAt] = null;
options.omitNull = false; options.omitNull = false;
return self.QueryInterface.bulkUpdate(self.getTableName(), attrValueHash, options.where, options, self._timestampAttributes.deletedAt); return self.QueryInterface.bulkUpdate(self.getTableName(), attrValueHash, options.where, options, self._timestampAttributes.deletedAt);
}
}).tap(function() { }).tap(function() {
// Run afterDestroy hook on each record individually // Run afterDestroy hook on each record individually
if (options.individualHooks) { if (options.individualHooks) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!