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

Commit f0e9aced by Ruben Bridgewater Committed by Jan Aagaard Meier

Fix model.count with includes and specified column (#6191)

1 parent 4f39a8a4
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
- [FIXED] `Int4` range not properly parsed [#5747](https://github.com/sequelize/sequelize/issues/5747) - [FIXED] `Int4` range not properly parsed [#5747](https://github.com/sequelize/sequelize/issues/5747)
- [FIXED] `upsert` does not fail anymore on not null validations [#5711](https://github.com/sequelize/sequelize/issues/5711) - [FIXED] `upsert` does not fail anymore on not null validations [#5711](https://github.com/sequelize/sequelize/issues/5711)
- [FIXED] Don't remove includes from count queries and unify findAndCount and count queries. [#6123](https://github.com/sequelize/sequelize/issues/6123) - [FIXED] Don't remove includes from count queries and unify findAndCount and count queries. [#6123](https://github.com/sequelize/sequelize/issues/6123)
- [FIXED] `Model.count` with `options.col` and `options.include` works properly now
## BC breaks: ## BC breaks:
- Range type bounds now default to [postgres default](https://www.postgresql.org/docs/9.5/static/rangetypes.html#RANGETYPES-CONSTRUCT) `[)` (inclusive, exclusive), previously was `()` (exclusive, exclusive) - Range type bounds now default to [postgres default](https://www.postgresql.org/docs/9.5/static/rangetypes.html#RANGETYPES-CONSTRUCT) `[)` (inclusive, exclusive), previously was `()` (exclusive, exclusive)
......
...@@ -1541,7 +1541,7 @@ class Model { ...@@ -1541,7 +1541,7 @@ class Model {
}).then(() => { }).then(() => {
let col = options.col || '*'; let col = options.col || '*';
if (options.include) { if (options.include) {
col = this.name + '.' + this.primaryKeyField; col = this.name + '.' + (options.col || this.primaryKeyField);
} }
Utils.mapOptionFieldNames(options, this); Utils.mapOptionFieldNames(options, this);
......
...@@ -150,5 +150,28 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -150,5 +150,28 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('should be able to specify column for COUNT() with includes', function() {
return this.sequelize.sync({ force: true }).then(() =>
this.User.bulkCreate([
{ username: 'ember' , age: 10},
{ username: 'angular' , age: 20},
{ username: 'mithril' , age: 10}
])
).then(() =>
this.User.count({
col: 'username',
distinct: true,
include: [this.Project]
})
).then((count) => {
expect(parseInt(count)).to.be.eql(3);
return this.User.count({
col: 'age',
distinct: true,
include: [this.Project]
});
}).then((count) => expect(parseInt(count)).to.be.eql(2));
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!