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 20e99e1f
authored
Feb 20, 2020
by
Tim Mensch
Committed by
GitHub
Feb 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model.count): distinct without any column generates invalid SQL (#11893)
1 parent
54d655d5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
1 deletions
lib/model.js
test/integration/model/count.test.js
lib/model.js
View file @
20e99e1
...
@@ -2031,7 +2031,9 @@ class Model {
...
@@ -2031,7 +2031,9 @@ class Model {
if
(
options
.
include
)
{
if
(
options
.
include
)
{
col
=
`
${
this
.
name
}
.
${
options
.
col
||
this
.
primaryKeyField
}
`
;
col
=
`
${
this
.
name
}
.
${
options
.
col
||
this
.
primaryKeyField
}
`
;
}
}
if
(
options
.
distinct
&&
col
===
'*'
)
{
col
=
this
.
primaryKeyField
;
}
options
.
plain
=
!
options
.
group
;
options
.
plain
=
!
options
.
group
;
options
.
dataType
=
new
DataTypes
.
INTEGER
();
options
.
dataType
=
new
DataTypes
.
INTEGER
();
options
.
includeIgnoreAttributes
=
false
;
options
.
includeIgnoreAttributes
=
false
;
...
...
test/integration/model/count.test.js
View file @
20e99e1
...
@@ -109,6 +109,21 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -109,6 +109,21 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
it
(
'should be able to specify NO column for COUNT() with DISTINCT'
,
function
()
{
return
this
.
User
.
bulkCreate
([
{
username
:
'ember'
,
age
:
10
},
{
username
:
'angular'
,
age
:
20
},
{
username
:
'mithril'
,
age
:
10
}
]).
then
(()
=>
{
return
this
.
User
.
count
({
distinct
:
true
});
})
.
then
(
count
=>
{
expect
(
count
).
to
.
be
.
eql
(
3
);
});
});
it
(
'should be able to use where clause on included models'
,
function
()
{
it
(
'should be able to use where clause on included models'
,
function
()
{
const
countOptions
=
{
const
countOptions
=
{
col
:
'username'
,
col
:
'username'
,
...
...
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