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 0fe77d6c
authored
Jul 22, 2018
by
David DOLCIMASCOLO
Committed by
Sushant
Jul 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(destroy): attributes updated in a beforeDestroy hook are now persisted on soft delete. (#9319)
1 parent
be8760db
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletions
lib/model.js
test/integration/hooks/destroy.test.js
lib/model.js
View file @
0fe77d6
...
@@ -3980,7 +3980,7 @@ class Model {
...
@@ -3980,7 +3980,7 @@ class Model {
if
(
this
.
constructor
.
_timestampAttributes
.
deletedAt
&&
options
.
force
===
false
)
{
if
(
this
.
constructor
.
_timestampAttributes
.
deletedAt
&&
options
.
force
===
false
)
{
const
attribute
=
this
.
constructor
.
rawAttributes
[
this
.
constructor
.
_timestampAttributes
.
deletedAt
];
const
attribute
=
this
.
constructor
.
rawAttributes
[
this
.
constructor
.
_timestampAttributes
.
deletedAt
];
const
field
=
attribute
.
field
||
this
.
constructor
.
_timestampAttributes
.
deletedAt
;
const
field
=
attribute
.
field
||
this
.
constructor
.
_timestampAttributes
.
deletedAt
;
const
values
=
{}
;
const
values
=
Utils
.
mapValueFieldNames
(
this
.
dataValues
,
this
.
changed
()
||
[],
this
.
constructor
)
;
values
[
field
]
=
new
Date
();
values
[
field
]
=
new
Date
();
where
[
field
]
=
attribute
.
hasOwnProperty
(
'defaultValue'
)
?
attribute
.
defaultValue
:
null
;
where
[
field
]
=
attribute
.
hasOwnProperty
(
'defaultValue'
)
?
attribute
.
defaultValue
:
null
;
...
...
test/integration/hooks/destroy.test.js
View file @
0fe77d6
...
@@ -76,6 +76,48 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
...
@@ -76,6 +76,48 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
});
});
});
});
});
});
describe
(
'with paranoid mode enabled'
,
()
=>
{
beforeEach
(
function
()
{
this
.
ParanoidUser
=
this
.
sequelize
.
define
(
'ParanoidUser'
,
{
username
:
DataTypes
.
STRING
,
updatedBy
:
DataTypes
.
INTEGER
,
virtualField
:
{
type
:
DataTypes
.
VIRTUAL
(
DataTypes
.
INTEGER
,
[
'updatedBy'
]),
get
()
{
return
this
.
updatedBy
-
1
;
}
}
},
{
paranoid
:
true
,
hooks
:
{
beforeDestroy
:
instance
=>
instance
.
updatedBy
=
1
}
});
});
it
(
'sets other changed values when soft deleting and a beforeDestroy hooks kicks in'
,
function
()
{
return
this
.
ParanoidUser
.
sync
({
force
:
true
})
.
then
(()
=>
this
.
ParanoidUser
.
create
({
username
:
'user1'
}))
.
then
(
user
=>
user
.
destroy
())
.
then
(()
=>
this
.
ParanoidUser
.
findOne
({
paranoid
:
false
}))
.
then
(
user
=>
{
expect
(
user
.
updatedBy
).
to
.
equal
(
1
);
});
});
it
(
'should not throw error when a beforeDestroy hook changes a virtual column'
,
function
()
{
this
.
ParanoidUser
.
beforeDestroy
(
instance
=>
instance
.
virtualField
=
2
);
return
this
.
ParanoidUser
.
sync
({
force
:
true
})
.
then
(()
=>
this
.
ParanoidUser
.
create
({
username
:
'user1'
}))
.
then
(
user
=>
user
.
destroy
())
.
then
(()
=>
this
.
ParanoidUser
.
findOne
({
paranoid
:
false
}))
.
then
(
user
=>
{
expect
(
user
.
virtualField
).
to
.
equal
(
0
);
});
});
});
});
});
});
});
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