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

Commit 5e5cdb78 by Jan Aagaard Meier

Fix an off by one error when running hooks in bulk update and delete. Closes #2054

1 parent 09441160
Showing with 16 additions and 16 deletions
......@@ -1030,6 +1030,10 @@ module.exports = (function() {
if (options && options.hooks === true) {
var tick = 0
var next = function(i) {
if (i >= records.length) {
return finished();
}
self.runHooks(self.options.hooks.afterDestroy, records[i], function(err, newValues) {
if (!!err) {
return finished(err)
......@@ -1038,10 +1042,6 @@ module.exports = (function() {
records[i].dataValues = !!newValues ? newValues.dataValues : records[i].dataValues
tick++
if (tick >= records.length) {
return finished()
}
next(tick)
})
}
......@@ -1058,6 +1058,10 @@ module.exports = (function() {
self.all({where: where}).error(function(err) { emitter.emit('error', err) })
.success(function(records) {
var next = function(i) {
if (i >= records.length) {
return runQuery(null, records)
}
self.runHooks(self.options.hooks.beforeDestroy, records[i], function(err, newValues) {
if (!!err) {
return runQuery(err)
......@@ -1066,10 +1070,6 @@ module.exports = (function() {
records[i].dataValues = !!newValues ? newValues.dataValues : records[i].dataValues
tick++
if (tick >= records.length) {
return runQuery(null, records)
}
next(tick)
})
}
......@@ -1145,6 +1145,10 @@ module.exports = (function() {
if (options && options.hooks === true && !!records && records.length > 0) {
var tick = 0
var next = function(i) {
if (i >= records.length) {
return finished(null, records)
}
self.runHooks(self.options.hooks.afterUpdate, records[i], function(err, newValues) {
if (!!err) {
return finished(err)
......@@ -1153,10 +1157,6 @@ module.exports = (function() {
records[i].dataValues = !!newValues ? newValues.dataValues : records[i].dataValues
tick++
if (tick >= records.length) {
return finished(null, records)
}
next(tick)
})
}
......@@ -1176,6 +1176,10 @@ module.exports = (function() {
}
var next = function(i) {
if (i >= records.length) {
return runQuery(null, records)
}
self.runHooks(self.options.hooks.beforeUpdate, records[i], function(err, newValues) {
if (!!err) {
return runQuery(err)
......@@ -1184,10 +1188,6 @@ module.exports = (function() {
records[i].dataValues = !!newValues ? newValues.dataValues : records[i].dataValues
tick++
if (tick >= records.length) {
return runQuery(null, records)
}
next(tick)
})
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!