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 4ff79dcc
authored
Nov 05, 2018
by
Tom Zellman
Committed by
Sushant
Nov 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(syntax): correct parentheses around union (#9813) (#10003) (#10121)
1 parent
c6c2d17b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
2 deletions
lib/dialects/abstract/query-generator.js
test/integration/model/findAll/separate.test.js
test/unit/sql/select.test.js
lib/dialects/abstract/query-generator.js
View file @
4ff79dc
...
...
@@ -1096,7 +1096,7 @@ const QueryGenerator = {
// Caching the base query and splicing the where part into it is consistently > twice
// as fast than generating from scratch each time for values.length >= 5
const
baseQuery
=
'('
+
this
.
selectQuery
(
const
baseQuery
=
'
SELECT * FROM
('
+
this
.
selectQuery
(
tableName
,
{
attributes
:
options
.
attributes
,
...
...
@@ -1107,7 +1107,7 @@ const QueryGenerator = {
model
},
model
).
replace
(
/;$/
,
''
)
+
')
'
;
).
replace
(
/;$/
,
''
)
+
')
AS sub'
;
// Every derived table must have its own alias
const
placeHolder
=
this
.
whereItemQuery
(
Op
.
placeholder
,
true
,
{
model
});
const
splicePos
=
baseQuery
.
indexOf
(
placeHolder
);
...
...
test/integration/model/findAll/separate.test.js
0 → 100644
View file @
4ff79dc
'use strict'
;
const
chai
=
require
(
'chai'
);
const
expect
=
chai
.
expect
;
const
Support
=
require
(
'../../support'
);
const
DataTypes
=
require
(
'../../../../lib/data-types'
);
const
Sequelize
=
require
(
'../../../../lib/sequelize'
);
const
current
=
Support
.
sequelize
;
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
describe
(
'findAll'
,
()
=>
{
describe
(
'separate with limit'
,
()
=>
{
it
(
'should not throw syntax error (union)'
,
()
=>
{
// #9813 testcase
const
Project
=
current
.
define
(
'Project'
,
{
name
:
DataTypes
.
STRING
});
const
LevelTwo
=
current
.
define
(
'LevelTwo'
,
{
name
:
DataTypes
.
STRING
});
const
LevelThree
=
current
.
define
(
'LevelThree'
,
{
type
:
DataTypes
.
INTEGER
});
Project
.
hasMany
(
LevelTwo
);
LevelTwo
.
belongsTo
(
Project
);
LevelTwo
.
hasMany
(
LevelThree
,
{
as
:
'type_ones'
});
LevelTwo
.
hasMany
(
LevelThree
,
{
as
:
'type_twos'
});
LevelThree
.
belongsTo
(
LevelTwo
);
return
current
.
sync
({
force
:
true
}).
then
(()
=>
{
return
Sequelize
.
Promise
.
all
([
Project
.
create
({
name
:
'testProject'
}),
LevelTwo
.
create
({
name
:
'testL21'
}),
LevelTwo
.
create
({
name
:
'testL22'
})
]);
}).
spread
((
project
,
level21
,
level22
)
=>
{
return
Sequelize
.
Promise
.
all
([
project
.
addLevelTwo
(
level21
),
project
.
addLevelTwo
(
level22
)
]);
}).
spread
(()
=>
{
// one include case
return
Project
.
findAll
({
where
:
{
name
:
'testProject'
},
include
:
[
{
model
:
LevelTwo
,
include
:
[
{
model
:
LevelThree
,
as
:
'type_ones'
,
where
:
{
type
:
0
},
separate
:
true
,
limit
:
1
,
order
:
[[
'createdAt'
,
'DESC'
]]
}
]
}
]
});
}).
then
(
projects
=>
{
expect
(
projects
).
to
.
have
.
length
(
1
);
expect
(
projects
[
0
].
LevelTwos
).
to
.
have
.
length
(
2
);
expect
(
projects
[
0
].
LevelTwos
[
0
].
type_ones
).
to
.
have
.
length
(
0
);
expect
(
projects
[
0
].
LevelTwos
[
1
].
type_ones
).
to
.
have
.
length
(
0
);
},
()
=>
{
expect
.
fail
();
}).
then
(()
=>
{
// two includes case
return
Project
.
findAll
({
where
:
{
name
:
'testProject'
},
include
:
[
{
model
:
LevelTwo
,
include
:
[
{
model
:
LevelThree
,
as
:
'type_ones'
,
where
:
{
type
:
0
},
separate
:
true
,
limit
:
1
,
order
:
[[
'createdAt'
,
'DESC'
]]
},
{
model
:
LevelThree
,
as
:
'type_twos'
,
where
:
{
type
:
1
},
separate
:
true
,
limit
:
1
,
order
:
[[
'createdAt'
,
'DESC'
]]
}
]
}
]
});
}).
then
(
projects
=>
{
expect
(
projects
).
to
.
have
.
length
(
1
);
expect
(
projects
[
0
].
LevelTwos
).
to
.
have
.
length
(
2
);
expect
(
projects
[
0
].
LevelTwos
[
0
].
type_ones
).
to
.
have
.
length
(
0
);
expect
(
projects
[
0
].
LevelTwos
[
1
].
type_ones
).
to
.
have
.
length
(
0
);
},
()
=>
{
expect
.
fail
();
});
});
});
});
});
test/unit/sql/select.test.js
View file @
4ff79dc
This diff is collapsed.
Click to expand it.
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