Skip to content

Commit

Permalink
fix(query-generator): allow Op as comparator in sequelize.where (#9124)
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting authored and sushantdhiman committed Mar 1, 2018
1 parent 5b6dae7 commit 476b08b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/dialects/abstract/query-generator.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/sequelize.js
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/unit/sql/where.test.js
Expand Up @@ -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'
});
});
});

0 comments on commit 476b08b

Please sign in to comment.