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 6401eba4
authored
Jan 17, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(fields): fix paranoid Model.destroy() and custom deletedAt field, closes #2879
1 parent
e403b488
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
lib/model.js
test/model/attributes/field.test.js
lib/model.js
View file @
6401eba
...
@@ -1470,8 +1470,10 @@ module.exports = (function() {
...
@@ -1470,8 +1470,10 @@ module.exports = (function() {
}).
then
(
function
()
{
}).
then
(
function
()
{
// Run delete query (or update if paranoid)
// Run delete query (or update if paranoid)
if
(
self
.
_timestampAttributes
.
deletedAt
&&
!
options
.
force
)
{
if
(
self
.
_timestampAttributes
.
deletedAt
&&
!
options
.
force
)
{
var
attrValueHash
=
{};
var
attrValueHash
=
{}
attrValueHash
[
self
.
_timestampAttributes
.
deletedAt
]
=
Utils
.
now
(
self
.
modelManager
.
sequelize
.
options
.
dialect
);
,
field
=
self
.
rawAttributes
[
self
.
_timestampAttributes
.
deletedAt
].
field
||
self
.
_timestampAttributes
.
deletedAt
;
attrValueHash
[
field
]
=
Utils
.
now
(
self
.
modelManager
.
sequelize
.
options
.
dialect
);
return
self
.
QueryInterface
.
bulkUpdate
(
self
.
getTableName
(
options
),
attrValueHash
,
options
.
where
,
options
,
self
.
rawAttributes
);
return
self
.
QueryInterface
.
bulkUpdate
(
self
.
getTableName
(
options
),
attrValueHash
,
options
.
where
,
options
,
self
.
rawAttributes
);
}
else
{
}
else
{
return
self
.
QueryInterface
.
bulkDelete
(
self
.
getTableName
(
options
),
options
.
where
,
options
,
self
);
return
self
.
QueryInterface
.
bulkDelete
(
self
.
getTableName
(
options
),
options
.
where
,
options
,
self
);
...
...
test/model/attributes/field.test.js
View file @
6401eba
...
@@ -500,7 +500,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -500,7 +500,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
});
it
(
'should work with paranoid
destroy
'
,
function
()
{
it
(
'should work with paranoid
instance.destroy()
'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
deletedAt
:
{
deletedAt
:
{
type
:
DataTypes
.
DATE
,
type
:
DataTypes
.
DATE
,
...
@@ -521,6 +521,28 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -521,6 +521,28 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
});
});
});
it
(
'should work with paranoid Model.destroy()'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
deletedAt
:
{
type
:
DataTypes
.
DATE
,
field
:
'deleted_at'
}
},
{
timestamps
:
true
,
paranoid
:
true
});
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
create
().
then
(
function
(
user
)
{
return
User
.
destroy
({
where
:
{
id
:
user
.
get
(
'id'
)}});
}).
then
(
function
()
{
return
User
.
findAll
().
then
(
function
(
users
)
{
expect
(
users
.
length
).
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