From 476b08be9caa196a78d9739cee7976612e2cd809 Mon Sep 17 00:00:00 2001 From: Jozef Hartinger Date: Thu, 1 Mar 2018 11:42:46 +0100 Subject: [PATCH] fix(query-generator): allow Op as comparator in sequelize.where (#9124) --- lib/dialects/abstract/query-generator.js | 4 ++++ lib/sequelize.js | 2 +- test/unit/sql/where.test.js | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/dialects/abstract/query-generator.js b/lib/dialects/abstract/query-generator.js index afd71c53c719..2bfd85da453f 100755 --- a/lib/dialects/abstract/query-generator.js +++ b/lib/dialects/abstract/query-generator.js @@ -1861,6 +1861,10 @@ const QueryGenerator = { handleSequelizeMethod(smth, tableName, factory, options, prepend) { let result; + if (this.OperatorMap.hasOwnProperty(smth.comparator)) { + smth.comparator = this.OperatorMap[smth.comparator]; + } + if (smth instanceof Utils.Where) { let value = smth.logic; let key; diff --git a/lib/sequelize.js b/lib/sequelize.js index bbc56e1c5d71..464d1793cc23 100755 --- a/lib/sequelize.js +++ b/lib/sequelize.js @@ -927,7 +927,7 @@ class Sequelize { * @see {@link Model.findAll} * * @param {Object} attr The attribute, which can be either an attribute object from `Model.rawAttributes` or a sequelize object, for example an instance of `sequelize.fn`. For simple string attributes, use the POJO syntax - * @param {string} [comparator='='] + * @param {String|Op} [comparator='='] * @param {String|Object} logic The condition. Can be both a simply type, or a further condition (`or`, `and`, `.literal` etc.) * @alias condition * @since v2.0.0-dev3 diff --git a/test/unit/sql/where.test.js b/test/unit/sql/where.test.js index 345fe049d9cb..31fe0b0e5780 100755 --- a/test/unit/sql/where.test.js +++ b/test/unit/sql/where.test.js @@ -1117,5 +1117,13 @@ suite(Support.getTestDialectTeaser('SQL'), () => { testsql(current.where(current.fn('lower', current.col('name')), null), { default: 'lower([name]) IS NULL' }); + + testsql(current.where(current.fn('SUM', current.col('hours')), '>', 0), { + default: 'SUM([hours]) > 0' + }); + + testsql(current.where(current.fn('SUM', current.col('hours')), current.Op.gt, 0), { + default: 'SUM([hours]) > 0' + }); }); });