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 7a90df5c
authored
Oct 01, 2019
by
George Maddocks
Committed by
Sushant
Oct 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(query): do not omit field when same field/name in fieldMap (#11492)
1 parent
c7138f5a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletions
lib/dialects/abstract/query.js
test/integration/sequelize.test.js
lib/dialects/abstract/query.js
View file @
7a90df5
...
...
@@ -248,7 +248,7 @@ class AbstractQuery {
if
(
this
.
options
.
fieldMap
)
{
const
fieldMap
=
this
.
options
.
fieldMap
;
results
=
results
.
map
(
result
=>
_
.
reduce
(
fieldMap
,
(
result
,
name
,
field
)
=>
{
if
(
result
[
field
]
!==
undefined
)
{
if
(
result
[
field
]
!==
undefined
&&
name
!==
field
)
{
result
[
name
]
=
result
[
field
];
delete
result
[
field
];
}
...
...
test/integration/sequelize.test.js
View file @
7a90df5
...
...
@@ -468,6 +468,18 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
});
});
it
(
'keeps field names that are mapped to the same name'
,
function
()
{
return
this
.
sequelize
.
query
(
this
.
insertQuery
).
then
(()
=>
{
return
this
.
sequelize
.
query
(
`SELECT * FROM
${
qq
(
this
.
User
.
tableName
)}
;`
,
{
type
:
'SELECT'
,
fieldMap
:
{
username
:
'username'
,
email_address
:
'email'
}
});
}).
then
(
users
=>
{
expect
(
users
[
0
].
username
).
to
.
be
.
equal
(
'john'
);
expect
(
users
[
0
].
email
).
to
.
be
.
equal
(
'john@gmail.com'
);
});
});
it
(
'reject if `values` and `options.replacements` are both passed'
,
function
()
{
return
this
.
sequelize
.
query
({
query
:
'select ? as foo, ? as bar'
,
values
:
[
1
,
2
]
},
{
raw
:
true
,
replacements
:
[
1
,
2
]
})
.
should
.
be
.
rejectedWith
(
Error
,
'Both `sql.values` and `options.replacements` cannot be set at the same time'
);
...
...
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