Skip to content

Commit 1130969

Browse files
fix: disregard empty and/or fields in buildSelect
1 parent 051098d commit 1130969

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/postgresql.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,13 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
623623
branches.push(stmtForClause.sql);
624624
}
625625
}
626-
stmt.merge({
627-
sql: '(' + branches.join(' ' + key.toUpperCase() + ' ') + ')',
628-
params: branchParams,
629-
});
630-
whereStmts.push(stmt);
626+
if (branches.length > 0) {
627+
stmt.merge({
628+
sql: '(' + branches.join(' ' + key.toUpperCase() + ' ') + ')',
629+
params: branchParams,
630+
});
631+
whereStmts.push(stmt);
632+
}
631633
continue;
632634
}
633635
// The value is not an array, fall back to regular fields

test/postgresql.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,15 @@ describe('postgresql connector', function() {
424424
});
425425
});
426426

427+
it('should disregard empty and/or fields', function(done) {
428+
Post.find({where: {and: []}}, function(err, post) {
429+
should.not.exist(err);
430+
should.exist(post);
431+
post.length.should.not.equal(0);
432+
done();
433+
});
434+
});
435+
427436
it('should preserve order of and/or in where', async function() {
428437
await Post.create({title: 'T3', content: 'C3', approved: false});
429438
// WHERE (title='T3' OR approved=false) AND (content='C2')

0 commit comments

Comments
 (0)