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

Commit 335efd6d by Jorrit Schippers Committed by Sushant

fix(selectQuery): don't add empty HAVING clause (#8931)

1 parent a4a0f883
...@@ -1159,12 +1159,14 @@ const QueryGenerator = { ...@@ -1159,12 +1159,14 @@ const QueryGenerator = {
// Add HAVING to sub or main query // Add HAVING to sub or main query
if (options.hasOwnProperty('having')) { if (options.hasOwnProperty('having')) {
options.having = this.getWhereConditions(options.having, tableName, model, options, false); options.having = this.getWhereConditions(options.having, tableName, model, options, false);
if (options.having) {
if (subQuery) { if (subQuery) {
subQueryItems.push(' HAVING ' + options.having); subQueryItems.push(' HAVING ' + options.having);
} else { } else {
mainQueryItems.push(' HAVING ' + options.having); mainQueryItems.push(' HAVING ' + options.having);
} }
} }
}
// Add ORDER to sub or main query // Add ORDER to sub or main query
if (options.order) { if (options.order) {
......
...@@ -417,6 +417,28 @@ if (dialect === 'mysql') { ...@@ -417,6 +417,28 @@ if (dialect === 'mysql') {
arguments: ['myTable', {where: {field: {$notRegexp: '^[h|a|t]'}}}], arguments: ['myTable', {where: {field: {$notRegexp: '^[h|a|t]'}}}],
expectation: "SELECT * FROM `myTable` WHERE `myTable`.`field` NOT REGEXP '^[h|a|t]';", expectation: "SELECT * FROM `myTable` WHERE `myTable`.`field` NOT REGEXP '^[h|a|t]';",
context: QueryGenerator context: QueryGenerator
}, {
title: 'Empty having',
arguments: ['myTable', function() {
return {
having: {}
};
}],
expectation: 'SELECT * FROM `myTable`;',
context: QueryGenerator,
needsSequelize: true
}, {
title: 'Having in subquery',
arguments: ['myTable', function() {
return {
subQuery: true,
tableAs: 'test',
having: { creationYear: { [Operators.gt]: 2002 } }
};
}],
expectation: 'SELECT `test`.* FROM (SELECT * FROM `myTable` AS `test` HAVING `creationYear` > 2002) AS `test`;',
context: QueryGenerator,
needsSequelize: true
} }
], ],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!