Fix for redis adapter when finding records filtered with multiple attributes

This commit is contained in:
Mikko Lehtinen 2012-10-09 21:19:38 +03:00
parent 01b9307e1c
commit 075699ee27
2 changed files with 12 additions and 1 deletions

View File

@ -60,7 +60,7 @@ var commands = Object.keys(redis.Multi.prototype).filter(function (n) {
commands.forEach(function (cmd) { commands.forEach(function (cmd) {
Client.prototype[cmd] = function (args, callback) { Client.prototype[cmd] = function (args, callback) {
var c = this._client, log; var c = this._client, log;
if (typeof args === 'string') { if (typeof args === 'string') {
@ -389,6 +389,7 @@ BridgeToRedis.prototype.all = function all(model, filter, callback) {
if (indexes && indexes.length) { if (indexes && indexes.length) {
innerSetUsed = true; innerSetUsed = true;
if (indexes.length > 1) { if (indexes.length > 1) {
indexes.unshift(dest);
trans.sinterstore(indexes); trans.sinterstore(indexes);
} else { } else {
dest = indexes[0]; dest = indexes[0];

View File

@ -418,6 +418,16 @@ function testOrm(schema) {
}); });
it('should find records filtered with multiple attributes', function (test) {
Post.create({title: 'title', content: 'content', published: true, date: 1}, function (err, post) {
Post.all({where: {title: 'title', date: 1}}, function (err, res) {
test.ok(res.length > 0, 'Exact match with string returns dataset');
test.done();
});
});
});
it('should handle hasMany relationship', function (test) { it('should handle hasMany relationship', function (test) {
User.create(function (err, u) { User.create(function (err, u) {
if (err) return console.log(err); if (err) return console.log(err);