Skip to content

Commit 02b9212

Browse files
committed
Ensure order of and/or clauses are preserved
Signed-off-by: Raymond Feng <enjoyjava@gmail.com>
1 parent ffb08f4 commit 02b9212

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/postgresql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
612612
}
613613
}
614614
stmt.merge({
615-
sql: branches.join(' ' + key.toUpperCase() + ' '),
615+
sql: '(' + branches.join(' ' + key.toUpperCase() + ' ') + ')',
616616
params: branchParams,
617617
});
618618
whereStmts.push(stmt);

test/postgresql.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ describe('postgresql connector', function() {
423423
done();
424424
});
425425
});
426+
427+
it('should preserve order of and/or in where', async function() {
428+
await Post.create({title: 'T3', content: 'C3', approved: false});
429+
// WHERE (title='T3' OR approved=false) AND (content='C2')
430+
const posts = await Post.find({where: {or: [{title: 'T3'},
431+
{approved: false}], content: 'C2'}});
432+
posts.length.should.equal(0);
433+
});
426434
});
427435

428436
context('pattern matching operators', function() {

0 commit comments

Comments
 (0)