From c33bc70756b9155ff9e5733ca0297334bad62881 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Tue, 6 Mar 2012 17:05:22 +0400 Subject: [PATCH] Support reverse sort for redis --- lib/adapters/redis.js | 3 ++- test/common_test.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/adapters/redis.js b/lib/adapters/redis.js index adc2637e..cdfbd7e0 100644 --- a/lib/adapters/redis.js +++ b/lib/adapters/redis.js @@ -203,6 +203,7 @@ BridgeToRedis.prototype.all = function all(model, filter, callback) { orders = [filter.order]; } orders.forEach(function (key) { + key = key.split(' ')[0]; if (props[key].type.name !== 'Number' && props[key].type.name !== 'Date') { allNumeric = false; } @@ -246,7 +247,7 @@ BridgeToRedis.prototype.all = function all(model, filter, callback) { orders.forEach(function (key) { var m = key.match(/\s+(A|DE)SC$/i); if (m) { - key = key.replace(/\s+DESC/i, ''); + key = key.replace(/\s+(A|DE)SC/i, ''); if (m[1] === 'DE') reverse = true; } if (key !== 'id') { diff --git a/test/common_test.js b/test/common_test.js index c88ea0ff..0bb3d694 100644 --- a/test/common_test.js +++ b/test/common_test.js @@ -52,8 +52,8 @@ function testOrm(schema) { it('should define class', function (test) { User = schema.define('User', { - name: String, - email: String, + name: { type: String, index: true }, + email: { type: String, index: true }, bio: Text, approved: Boolean, joinedAt: Date,