Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
return nothing on e.g. where({id:[]})
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Waldmann committed May 22, 2014
1 parent 6a4de65 commit 71aaf72
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/stores/sql/helper.js
Expand Up @@ -46,6 +46,12 @@ exports.applyConditions = function(conditions, table_map, query, having){
if(table_map[name_tree.join('.')]) table = table_map[name_tree.join('.')];
}

if(value instanceof Array && value.length === 0){
value = null;
operator = 'is';
}


if(value instanceof Array){
var condition;

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "openrecord",
"version": "0.16.3",
"version": "0.16.5",
"description": "Active record like ORM for nodejs",
"keywords": ["orm", "record", "sql", "sqlite3", "postgres", "pg", "mysql", "database", "activerecord", "promise", "rest", "restify", "nested set"],
"author": "Philipp Waldmann <philipp.waldmann@s-team.at>",
Expand Down
11 changes: 11 additions & 0 deletions test/sql/__shared/conditions-test.js
Expand Up @@ -287,6 +287,17 @@ module.exports = function(title, beforeFn, afterFn, store_conf){
});
});


it('finds nothing with empty array in condition (IS NULL))', function(next){
store.ready(function(){
var User = store.Model('User');
User.where({login: []}).exec(function(result){
result.length.should.be.equal(0);
next();
});
});
});


});

Expand Down

0 comments on commit 71aaf72

Please sign in to comment.