Skip to content

Commit ecf91b5

Browse files
abhilashmurthydhmlau
authored andcommitted
fix: disregard empty and/or fields
Signed-off-by: Abhilash Murthy <abhilashmurthy92@gmail.com>
1 parent ce2310e commit ecf91b5

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
@@ -625,11 +625,13 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
625625
branches.push(stmtForClause.sql);
626626
}
627627
}
628-
stmt.merge({
629-
sql: '(' + branches.join(' ' + key.toUpperCase() + ' ') + ')',
630-
params: branchParams,
631-
});
632-
whereStmts.push(stmt);
628+
if (branches.length > 0) {
629+
stmt.merge({
630+
sql: '(' + branches.join(' ' + key.toUpperCase() + ' ') + ')',
631+
params: branchParams,
632+
});
633+
whereStmts.push(stmt);
634+
}
633635
continue;
634636
}
635637
// 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
@@ -442,6 +442,15 @@ describe('postgresql connector', function() {
442442
});
443443
});
444444

445+
it('should disregard empty and/or fields', function(done) {
446+
Post.find({where: {and: []}}, function(err, post) {
447+
should.not.exist(err);
448+
should.exist(post);
449+
post.length.should.not.equal(0);
450+
done();
451+
});
452+
});
453+
445454
it('should preserve order of and/or in where', async function() {
446455
await Post.create({title: 'T3', content: 'C3', approved: false});
447456
// WHERE (title='T3' OR approved=false) AND (content='C2')

0 commit comments

Comments
 (0)