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

Commit f3671912 by Thodoris Sotiropoulos Committed by GitHub

fix(query-generator): do not generate GROUP BY clause if options.group is empty (#12343)

1 parent 7afd5899
......@@ -1333,9 +1333,9 @@ class QueryGenerator {
if (options.group) {
options.group = Array.isArray(options.group) ? options.group.map(t => this.aliasGrouping(t, model, mainTable.as, options)).join(', ') : this.aliasGrouping(options.group, model, mainTable.as, options);
if (subQuery) {
if (subQuery && options.group) {
subQueryItems.push(` GROUP BY ${options.group}`);
} else {
} else if (options.group) {
mainQueryItems.push(` GROUP BY ${options.group}`);
}
}
......
'use strict';
const Support = require('../support'),
DataTypes = require('../../../lib/data-types'),
util = require('util'),
expectsql = Support.expectsql,
current = Support.sequelize,
sql = current.dialect.queryGenerator;
describe(Support.getTestDialectTeaser('SQL'), () => {
describe('group', () => {
const testsql = function(options, expectation) {
const model = options.model;
it(util.inspect(options, { depth: 2 }), () => {
return expectsql(
sql.selectQuery(
options.table || model && model.getTableName(),
options,
options.model
),
expectation
);
});
};
const User = Support.sequelize.define('User', {
name: {
type: DataTypes.STRING,
field: 'name',
allowNull: false
}
});
testsql({
model: User,
group: ['name']
}, {
default: 'SELECT * FROM `Users` AS `User` GROUP BY `name`;',
postgres: 'SELECT * FROM "Users" AS "User" GROUP BY "name";',
mssql: 'SELECT * FROM [Users] AS [User] GROUP BY [name];'
});
testsql({
model: User,
group: []
}, {
default: 'SELECT * FROM `Users` AS `User`;',
postgres: 'SELECT * FROM "Users" AS "User";',
mssql: 'SELECT * FROM [Users] AS [User];'
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!