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 2e4b9b26
authored
Aug 21, 2015
by
Nuno Sousa
Committed by
Jan Aagaard Meier
Oct 08, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve field mapping in `destroy()` and `increment()`
1 parent
da57c5b5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
19 deletions
lib/instance.js
lib/instance.js
View file @
2e4b9b2
...
@@ -821,18 +821,13 @@ Instance.prototype.destroy = function(options) {
...
@@ -821,18 +821,13 @@ Instance.prototype.destroy = function(options) {
return
this
.
Model
.
runHooks
(
'beforeDestroy'
,
this
,
options
);
return
this
.
Model
.
runHooks
(
'beforeDestroy'
,
this
,
options
);
}
}
}).
then
(
function
()
{
}).
then
(
function
()
{
var
where
;
var
where
=
Utils
.
mapOptionFieldNames
({
where
:
this
.
where
()
},
this
.
Model
).
where
;
if
(
this
.
Model
.
_timestampAttributes
.
deletedAt
&&
options
.
force
===
false
)
{
if
(
this
.
Model
.
_timestampAttributes
.
deletedAt
&&
options
.
force
===
false
)
{
this
.
setDataValue
(
this
.
Model
.
_timestampAttributes
.
deletedAt
,
new
Date
());
this
.
setDataValue
(
this
.
Model
.
_timestampAttributes
.
deletedAt
,
new
Date
());
return
this
.
save
(
_
.
extend
({},
options
,
{
hooks
:
false
}));
return
this
.
save
(
_
.
extend
({},
options
,
{
hooks
:
false
}));
}
else
{
}
else
{
where
=
{};
return
this
.
sequelize
.
getQueryInterface
().
delete
(
this
,
this
.
Model
.
getTableName
(
options
),
where
,
_
.
assign
({
type
:
QueryTypes
.
DELETE
,
limit
:
null
},
options
));
var
primaryKeys
=
this
.
Model
.
primaryKeyAttributes
;
for
(
var
i
=
0
;
i
<
primaryKeys
.
length
;
i
++
)
{
where
[
this
.
Model
.
rawAttributes
[
primaryKeys
[
i
]].
field
]
=
this
.
get
(
primaryKeys
[
i
],
{
raw
:
true
});
}
return
this
.
sequelize
.
getQueryInterface
().
delete
(
this
,
this
.
Model
.
getTableName
(
options
),
where
,
_
.
defaults
(
options
,
{
type
:
QueryTypes
.
DELETE
,
limit
:
null
}));
}
}
}).
tap
(
function
()
{
}).
tap
(
function
()
{
// Run after hook
// Run after hook
...
@@ -906,22 +901,11 @@ Instance.prototype.restore = function(options) {
...
@@ -906,22 +901,11 @@ Instance.prototype.restore = function(options) {
* @return {Promise<this>}
* @return {Promise<this>}
*/
*/
Instance
.
prototype
.
increment
=
function
(
fields
,
options
)
{
Instance
.
prototype
.
increment
=
function
(
fields
,
options
)
{
var
identifier
=
this
.
where
()
var
identifier
=
Utils
.
mapOptionFieldNames
({
where
:
this
.
where
()
},
this
.
Model
).
where
,
updatedAtAttr
=
this
.
Model
.
_timestampAttributes
.
updatedAt
,
updatedAtAttr
=
this
.
Model
.
_timestampAttributes
.
updatedAt
,
values
=
{}
,
values
=
{}
,
where
;
,
where
;
if
(
identifier
)
{
for
(
var
attrName
in
identifier
)
{
// Field name mapping
var
rawAttribute
=
this
.
Model
.
rawAttributes
[
attrName
];
if
(
rawAttribute
.
field
&&
rawAttribute
.
field
!==
rawAttribute
.
fieldName
)
{
identifier
[
this
.
Model
.
rawAttributes
[
attrName
].
field
]
=
identifier
[
attrName
];
delete
identifier
[
attrName
];
}
}
}
options
=
_
.
defaults
({},
options
,
{
options
=
_
.
defaults
({},
options
,
{
by
:
1
,
by
:
1
,
attributes
:
{},
attributes
:
{},
...
...
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