不要怂,就是干,撸起袖子干!

Commit 20e99e1f by Tim Mensch Committed by GitHub

fix(model.count): distinct without any column generates invalid SQL (#11893)

1 parent 54d655d5
...@@ -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;
......
...@@ -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',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!