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 56d07c6d
authored
Jun 27, 2020
by
Shahar Hadas
Committed by
GitHub
Jun 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(mssql): insert/upsert operations do not return all fields (#12434)
1 parent
ad1c1537
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
1 deletions
lib/dialects/mssql/query.js
test/integration/model/create.test.js
test/integration/model/upsert.test.js
lib/dialects/mssql/query.js
View file @
56d07c6
...
...
@@ -204,7 +204,8 @@ class Query extends AbstractQuery {
return
this
.
handleShowIndexesQuery
(
data
);
}
if
(
this
.
isUpsertQuery
())
{
return
data
[
0
];
this
.
handleInsertQuery
(
data
);
return
this
.
instance
||
data
[
0
];
}
if
(
this
.
isCallQuery
())
{
return
data
[
0
];
...
...
@@ -391,6 +392,18 @@ class Query extends AbstractQuery {
id
=
id
||
autoIncrementAttributeAlias
&&
results
&&
results
[
0
][
autoIncrementAttributeAlias
];
this
.
instance
[
autoIncrementAttribute
]
=
id
;
if
(
this
.
instance
.
dataValues
)
{
for
(
const
key
in
results
[
0
])
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
results
[
0
],
key
))
{
const
record
=
results
[
0
][
key
];
const
attr
=
_
.
find
(
this
.
model
.
rawAttributes
,
attribute
=>
attribute
.
fieldName
===
key
||
attribute
.
field
===
key
);
this
.
instance
.
dataValues
[
attr
&&
attr
.
fieldName
||
key
]
=
record
;
}
}
}
}
}
}
...
...
test/integration/model/create.test.js
View file @
56d07c6
...
...
@@ -1454,6 +1454,23 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
if
(
current
.
dialect
.
supports
.
returnValues
)
{
it
(
'should return default value set by the database (create)'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
,
code
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
Sequelize
.
literal
(
2020
)
}
});
return
User
.
sync
({
force
:
true
})
.
then
(()
=>
User
.
create
({
name
:
'FooBar'
}))
.
then
(
user
=>
{
expect
(
user
.
name
).
to
.
be
.
equal
(
'FooBar'
);
expect
(
user
.
code
).
to
.
be
.
equal
(
2020
);
});
});
}
it
(
'should support logging'
,
function
()
{
const
spy
=
sinon
.
spy
();
...
...
test/integration/model/upsert.test.js
View file @
56d07c6
...
...
@@ -620,6 +620,21 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
it
(
'should return default value set by the database (upsert)'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
{
type
:
DataTypes
.
STRING
,
primaryKey
:
true
},
code
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
Sequelize
.
literal
(
2020
)
}
});
return
User
.
sync
({
force
:
true
})
.
then
(()
=>
User
.
upsert
({
name
:
'Test default value'
},
{
returning
:
true
}))
.
then
(([
user
,
created
])
=>
{
expect
(
user
.
name
).
to
.
be
.
equal
(
'Test default value'
);
expect
(
user
.
code
).
to
.
be
.
equal
(
2020
);
expect
(
created
).
to
.
be
.
true
;
});
});
}
});
}
...
...
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