Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 5e5cdb78
authored
Jul 23, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix an off by one error when running hooks in bulk update and delete. Closes #2054
1 parent
09441160
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
20 deletions
lib/dao-factory.js
test/hooks.test.js
lib/dao-factory.js
View file @
5e5cdb7
...
...
@@ -155,14 +155,14 @@ module.exports = (function() {
}
Util
.
inherits
(
this
.
DAO
,
DAO
);
this
.
_timestampAttributes
=
{}
if
(
this
.
options
.
timestamps
)
{
if
(
this
.
options
.
createdAt
)
{
this
.
_timestampAttributes
.
createdAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
createdAt
,
this
.
options
.
underscored
)
}
if
(
this
.
options
.
updatedAt
)
{
this
.
_timestampAttributes
.
updatedAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
)
this
.
_timestampAttributes
.
updatedAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
)
}
if
(
this
.
options
.
paranoid
&&
this
.
options
.
deletedAt
)
{
this
.
_timestampAttributes
.
deletedAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)
...
...
@@ -603,7 +603,7 @@ module.exports = (function() {
DAOFactory
.
prototype
.
count
=
function
(
options
)
{
options
=
Utils
.
_
.
clone
(
options
||
{})
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
col
=
this
.
sequelize
.
col
(
'*'
)
if
(
options
.
include
)
{
...
...
@@ -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
)
})
}
...
...
test/hooks.test.js
View file @
5e5cdb7
...
...
@@ -1883,7 +1883,7 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
hookCalled
++
next
()
})
B
.
hasMany
(
A
)
A
.
hasMany
(
B
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment