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 96f4166a
authored
Jul 11, 2020
by
Ariel Barabas
Committed by
GitHub
Jul 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(upsert): set isNewRecord to false when upserting (#12447) (#12485)
1 parent
45d9c226
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
2 deletions
lib/dialects/mariadb/query.js
lib/model.js
test/integration/instance.test.js
test/unit/model/upsert.test.js
lib/dialects/mariadb/query.js
View file @
96f4166
...
@@ -96,7 +96,7 @@ class Query extends AbstractQuery {
...
@@ -96,7 +96,7 @@ class Query extends AbstractQuery {
return
data
.
affectedRows
;
return
data
.
affectedRows
;
}
}
if
(
this
.
isUpsertQuery
())
{
if
(
this
.
isUpsertQuery
())
{
return
[
null
,
data
.
affectedRows
===
1
];
return
[
result
,
data
.
affectedRows
===
1
];
}
}
if
(
this
.
isInsertQuery
(
data
))
{
if
(
this
.
isInsertQuery
(
data
))
{
this
.
handleInsertQuery
(
data
);
this
.
handleInsertQuery
(
data
);
...
...
lib/model.js
View file @
96f4166
...
@@ -2469,6 +2469,9 @@ class Model {
...
@@ -2469,6 +2469,9 @@ class Model {
}
}
const
result
=
await
this
.
queryInterface
.
upsert
(
this
.
getTableName
(
options
),
insertValues
,
updateValues
,
instance
.
where
(),
options
);
const
result
=
await
this
.
queryInterface
.
upsert
(
this
.
getTableName
(
options
),
insertValues
,
updateValues
,
instance
.
where
(),
options
);
const
[
record
]
=
result
;
record
.
isNewRecord
=
false
;
if
(
options
.
hooks
)
{
if
(
options
.
hooks
)
{
await
this
.
runHooks
(
'afterUpsert'
,
result
,
options
);
await
this
.
runHooks
(
'afterUpsert'
,
result
,
options
);
return
result
;
return
result
;
...
...
test/integration/instance.test.js
View file @
96f4166
...
@@ -85,6 +85,12 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
...
@@ -85,6 +85,12 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
expect
(
user
.
isNewRecord
).
to
.
not
.
be
.
ok
;
expect
(
user
.
isNewRecord
).
to
.
not
.
be
.
ok
;
});
});
it
(
'returns false for upserted objects'
,
async
function
()
{
// adding id here so MSSQL doesn't fail. It needs a primary key to upsert
const
[
user
]
=
await
this
.
User
.
upsert
({
id
:
2
,
username
:
'user'
});
expect
(
user
.
isNewRecord
).
to
.
not
.
be
.
ok
;
});
it
(
'returns false for objects found by find method'
,
async
function
()
{
it
(
'returns false for objects found by find method'
,
async
function
()
{
await
this
.
User
.
create
({
username
:
'user'
});
await
this
.
User
.
create
({
username
:
'user'
});
const
user
=
await
this
.
User
.
create
({
username
:
'user'
});
const
user
=
await
this
.
User
.
create
({
username
:
'user'
});
...
...
test/unit/model/upsert.test.js
View file @
96f4166
...
@@ -43,7 +43,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -43,7 +43,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
query
=
sinon
.
stub
(
current
,
'query'
).
resolves
();
this
.
query
=
sinon
.
stub
(
current
,
'query'
).
resolves
();
this
.
stub
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'upsert'
).
resolves
([
t
rue
,
undefined
]);
this
.
stub
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'upsert'
).
resolves
([
t
his
.
User
.
build
(),
true
]);
});
});
afterEach
(
function
()
{
afterEach
(
function
()
{
...
...
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