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 36580d98
authored
Nov 06, 2014
by
Seth Samuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return failure from undestroy before hooks execute
1 parent
1c597126
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
16 deletions
lib/instance.js
lib/model.js
lib/instance.js
View file @
36580d9
...
...
@@ -766,6 +766,8 @@ module.exports = (function() {
* @return {Promise<undefined>}
*/
Instance
.
prototype
.
undestroy
=
function
(
options
)
{
if
(
!
this
.
Model
.
_timestampAttributes
.
deletedAt
)
return
Promise
.
reject
(
new
Error
(
"Model is not paranoid"
));
options
=
Utils
.
_
.
extend
({
hooks
:
true
,
force
:
false
...
...
@@ -780,14 +782,8 @@ module.exports = (function() {
return
self
.
Model
.
runHooks
(
'beforeUndestroy'
,
self
,
options
);
}
}).
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
;
return
self
.
save
(
_
.
extend
(
_
.
clone
(
options
),
{
hooks
:
false
,
omitNull
:
false
}));
}
self
.
dataValues
[
self
.
Model
.
_timestampAttributes
.
deletedAt
]
=
null
;
return
self
.
save
(
_
.
extend
(
_
.
clone
(
options
),
{
hooks
:
false
,
omitNull
:
false
}));
}).
tap
(
function
(
result
)
{
// Run after hook
if
(
options
.
hooks
)
{
...
...
lib/model.js
View file @
36580d9
...
...
@@ -1399,6 +1399,8 @@ module.exports = (function() {
* @return {Promise<undefined>}
*/
Model
.
prototype
.
undestroy
=
function
(
options
)
{
if
(
!
this
.
_timestampAttributes
.
deletedAt
)
return
Promise
.
reject
(
new
Error
(
"Model is not paranoid"
));
options
=
Utils
.
_
.
extend
({
hooks
:
true
,
individualHooks
:
false
...
...
@@ -1429,14 +1431,10 @@ module.exports = (function() {
}
}).
then
(
function
()
{
// Run undelete query
if
(
!
self
.
_timestampAttributes
.
deletedAt
)
{
return
Promise
.
reject
(
new
Error
(
"Model is not paranoid"
));
}
else
{
var
attrValueHash
=
{};
attrValueHash
[
self
.
_timestampAttributes
.
deletedAt
]
=
null
;
options
.
omitNull
=
false
;
return
self
.
QueryInterface
.
bulkUpdate
(
self
.
getTableName
(),
attrValueHash
,
options
.
where
,
options
,
self
.
_timestampAttributes
.
deletedAt
);
}
var
attrValueHash
=
{};
attrValueHash
[
self
.
_timestampAttributes
.
deletedAt
]
=
null
;
options
.
omitNull
=
false
;
return
self
.
QueryInterface
.
bulkUpdate
(
self
.
getTableName
(),
attrValueHash
,
options
.
where
,
options
,
self
.
_timestampAttributes
.
deletedAt
);
}).
tap
(
function
()
{
// Run afterDestroy hook on each record individually
if
(
options
.
individualHooks
)
{
...
...
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