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 33c5a31f
authored
Aug 24, 2017
by
Chad Huntley
Committed by
Sushant
Aug 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(upsert): use correct timestamp field names when generating query (#8088)
1 parent
9bfbee6c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
lib/model.js
test/unit/model/upsert.test.js
lib/model.js
View file @
33c5a31
...
@@ -2192,10 +2192,12 @@ class Model {
...
@@ -2192,10 +2192,12 @@ class Model {
// Attach createdAt
// Attach createdAt
if
(
createdAtAttr
&&
!
updateValues
[
createdAtAttr
])
{
if
(
createdAtAttr
&&
!
updateValues
[
createdAtAttr
])
{
insertValues
[
createdAtAttr
]
=
this
.
_getDefaultTimestamp
(
createdAtAttr
)
||
now
;
const
field
=
this
.
rawAttributes
[
createdAtAttr
].
field
||
createdAtAttr
;
insertValues
[
field
]
=
this
.
_getDefaultTimestamp
(
createdAtAttr
)
||
now
;
}
}
if
(
updatedAtAttr
&&
!
insertValues
[
updatedAtAttr
])
{
if
(
updatedAtAttr
&&
!
insertValues
[
updatedAtAttr
])
{
insertValues
[
updatedAtAttr
]
=
updateValues
[
updatedAtAttr
]
=
this
.
_getDefaultTimestamp
(
updatedAtAttr
)
||
now
;
const
field
=
this
.
rawAttributes
[
updatedAtAttr
].
field
||
updatedAtAttr
;
insertValues
[
field
]
=
updateValues
[
field
]
=
this
.
_getDefaultTimestamp
(
updatedAtAttr
)
||
now
;
}
}
// Build adds a null value for the primary key, if none was given by the user.
// Build adds a null value for the primary key, if none was given by the user.
...
...
test/unit/model/upsert.test.js
View file @
33c5a31
...
@@ -28,9 +28,19 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -28,9 +28,19 @@ describe(Support.getTestDialectTeaser('Model'), () => {
secretValue
:
{
secretValue
:
{
type
:
DataTypes
.
INTEGER
,
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
allowNull
:
false
},
createdAt
:
{
type
:
DataTypes
.
DATE
,
field
:
'created_at'
}
}
});
});
const
UserNoTime
=
current
.
define
(
'UserNoTime'
,
{
name
:
DataTypes
.
STRING
},
{
timestamps
:
false
});
before
(
function
()
{
before
(
function
()
{
this
.
query
=
current
.
query
;
this
.
query
=
current
.
query
;
current
.
query
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
current
.
query
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
...
@@ -56,6 +66,31 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -56,6 +66,31 @@ describe(Support.getTestDialectTeaser('Model'), () => {
})).
not
.
to
.
be
.
rejectedWith
(
current
.
ValidationError
);
})).
not
.
to
.
be
.
rejectedWith
(
current
.
ValidationError
);
});
});
it
(
'creates new record with correct field names'
,
()
=>
{
return
User
.
upsert
({
name
:
'Young Cat'
,
virtualValue
:
999
})
.
then
(()
=>
{
expect
(
Object
.
keys
(
self
.
stub
.
getCall
(
0
).
args
[
1
])).
to
.
deep
.
equal
([
'name'
,
'value'
,
'created_at'
,
'updatedAt'
]);
});
});
it
(
'creates new record with timestamps disabled'
,
()
=>
{
return
UserNoTime
.
upsert
({
name
:
'Young Cat'
})
.
then
(()
=>
{
expect
(
Object
.
keys
(
self
.
stub
.
getCall
(
0
).
args
[
1
])).
to
.
deep
.
equal
([
'name'
]);
});
});
it
(
'updates all changed fields by default'
,
()
=>
{
it
(
'updates all changed fields by default'
,
()
=>
{
return
User
return
User
.
upsert
({
.
upsert
({
...
...
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