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 100b2ddb
authored
Jan 23, 2019
by
Miroslav
Committed by
Sushant
Jan 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model/update): propagate paranoid to individualHooks query (#10369)
1 parent
d610e949
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletions
lib/model.js
test/integration/model.test.js
lib/model.js
View file @
100b2dd
...
@@ -2907,7 +2907,13 @@ class Model {
...
@@ -2907,7 +2907,13 @@ class Model {
// Get instances and run beforeUpdate hook on each record individually
// Get instances and run beforeUpdate hook on each record individually
if
(
options
.
individualHooks
)
{
if
(
options
.
individualHooks
)
{
return
this
.
findAll
({
where
:
options
.
where
,
transaction
:
options
.
transaction
,
logging
:
options
.
logging
,
benchmark
:
options
.
benchmark
}).
then
(
_instances
=>
{
return
this
.
findAll
({
where
:
options
.
where
,
transaction
:
options
.
transaction
,
logging
:
options
.
logging
,
benchmark
:
options
.
benchmark
,
paranoid
:
options
.
paranoid
}).
then
(
_instances
=>
{
instances
=
_instances
;
instances
=
_instances
;
if
(
!
instances
.
length
)
{
if
(
!
instances
.
length
)
{
return
[];
return
[];
...
...
test/integration/model.test.js
View file @
100b2dd
...
@@ -1194,6 +1194,36 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -1194,6 +1194,36 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
it
(
'calls update hook for soft deleted objects'
,
function
()
{
const
hookSpy
=
sinon
.
spy
();
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
},
{
paranoid
:
true
,
hooks
:
{
beforeUpdate
:
hookSpy
}
}
);
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
User
.
bulkCreate
([
{
username
:
'user1'
}
]);
}).
then
(()
=>
{
return
User
.
destroy
({
where
:
{
username
:
'user1'
}
});
}).
then
(()
=>
{
return
User
.
update
(
{
username
:
'updUser1'
},
{
paranoid
:
false
,
where
:
{
username
:
'user1'
},
individualHooks
:
true
});
}).
then
(()
=>
{
return
User
.
findOne
({
where
:
{
username
:
'updUser1'
},
paranoid
:
false
});
}).
then
(
user
=>
{
expect
(
user
).
to
.
not
.
be
.
null
;
expect
(
user
.
username
).
to
.
eq
(
'updUser1'
);
expect
(
hookSpy
).
to
.
have
.
been
.
called
;
});
});
if
(
dialect
===
'postgres'
)
{
if
(
dialect
===
'postgres'
)
{
it
(
'returns the affected rows if `options.returning` is true'
,
function
()
{
it
(
'returns the affected rows if `options.returning` is true'
,
function
()
{
const
data
=
[{
username
:
'Peter'
,
secretValue
:
'42'
},
const
data
=
[{
username
:
'Peter'
,
secretValue
:
'42'
},
...
...
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