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 d5e4a10f
authored
Sep 08, 2019
by
Sushant
Committed by
GitHub
Sep 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: unknown column with subquery joins (#11404)
1 parent
2172333c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
lib/dialects/abstract/query-generator.js
test/integration/include/findAll.test.js
lib/dialects/abstract/query-generator.js
View file @
d5e4a10
...
...
@@ -1186,10 +1186,10 @@ class QueryGenerator {
mainJoinQueries
=
mainJoinQueries
.
concat
(
joinQueries
.
mainQuery
);
if
(
joinQueries
.
attributes
.
main
.
length
>
0
)
{
attributes
.
main
=
attributes
.
main
.
concat
(
joinQueries
.
attributes
.
main
);
attributes
.
main
=
_
.
uniq
(
attributes
.
main
.
concat
(
joinQueries
.
attributes
.
main
)
);
}
if
(
joinQueries
.
attributes
.
subQuery
.
length
>
0
)
{
attributes
.
subQuery
=
attributes
.
subQuery
.
concat
(
joinQueries
.
attributes
.
subQuery
);
attributes
.
subQuery
=
_
.
uniq
(
attributes
.
subQuery
.
concat
(
joinQueries
.
attributes
.
subQuery
)
);
}
}
}
...
...
@@ -1671,6 +1671,7 @@ class QueryGenerator {
else asRight = `
$
{
asLeft
}
->
$
{
asRight
}
`;
let joinOn = `
$
{
this
.
quoteTable
(
asLeft
)}.
$
{
this
.
quoteIdentifier
(
fieldLeft
)}
`;
const subqueryAttributes = [];
if (topLevelInfo.options.groupedLimit && parentIsTop || topLevelInfo.subQuery && include.parent.subQuery && !include.subQuery) {
if (parentIsTop) {
...
...
@@ -1679,6 +1680,10 @@ class QueryGenerator {
// Check for potential aliased JOIN condition
joinOn = this._getAliasForField(tableName, attrLeft, topLevelInfo.options) || `
$
{
tableName
}.
$
{
this
.
quoteIdentifier
(
attrLeft
)}
`;
if (topLevelInfo.subQuery) {
subqueryAttributes.push(`
$
{
tableName
}.
$
{
this
.
quoteIdentifier
(
fieldLeft
)}
`);
}
} else {
const joinSource = `
$
{
asLeft
.
replace
(
/->/g
,
'.'
)}.
$
{
attrLeft
}
`;
...
...
@@ -1716,7 +1721,7 @@ class QueryGenerator {
condition: joinOn,
attributes: {
main: [],
subQuery:
[]
subQuery:
subqueryAttributes
}
};
}
...
...
test/integration/include/findAll.test.js
View file @
d5e4a10
...
...
@@ -2091,5 +2091,29 @@ describe(Support.getTestDialectTeaser('Include'), () => {
});
});
});
it
(
'should be able to generate a correct request for entity with 1:n and m:1 associations and limit'
,
function
()
{
return
this
.
fixtureA
().
then
(()
=>
{
return
this
.
models
.
Product
.
findAll
({
attributes
:
[
'title'
],
include
:
[
{
model
:
this
.
models
.
User
},
{
model
:
this
.
models
.
Price
}
],
limit
:
10
}).
then
(
products
=>
{
expect
(
products
).
to
.
be
.
an
(
'array'
);
expect
(
products
).
to
.
be
.
lengthOf
(
10
);
for
(
const
product
of
products
)
{
expect
(
product
.
title
).
to
.
be
.
a
(
'string'
);
// checking that internally added fields used to handle 'BelongsTo' associations are not leaked to result
expect
(
product
.
UserId
).
to
.
be
.
equal
(
undefined
);
// checking that included models are on their places
expect
(
product
.
User
).
to
.
satisfy
(
User
=>
User
===
null
||
User
instanceof
this
.
models
.
User
);
expect
(
product
.
Prices
).
to
.
be
.
an
(
'array'
);
}
});
});
});
});
});
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