Permalink
Browse files

Fixed id retrievals to work with the new and old id schemes (thanks P…

…ier Paolo Ramon)
  • Loading branch information...
1 parent d85e4dd commit 76403b3cfa8f01a43e02ddfa299571cabfc33f5f @maritz committed Oct 3, 2011
Showing with 20 additions and 14 deletions.
  1. +1 −0 .npmignore
  2. +6 −3 lib/relations.js
  3. +12 −9 lib/retrieve.js
  4. +1 −2 test/featureTests.js
View
@@ -1 +1,2 @@
nohm.komodoproject
+experiments.js
View
@@ -53,9 +53,12 @@ exports.getAll = function getAll(objName, name) {
console.log('getAll has got a non-array value');
value = [];
} else {
- /*value = value.map(function (val) {
- return parseInt(val.toString(), 10);
- });*/
+ value = value.map(function (val) {
+ if (self.idGenerator === 'increment') {
+ val = parseInt(val.toString(), 10)
+ }
+ return val;
+ });
}
callback.call(self, err, value);
});
View
@@ -83,8 +83,10 @@ exports.find = function find(searches, callback) {
callback(err);
} else {
values.forEach(function (val, key) {
- var parsed = parseInt(val, 10);
- if (!isNaN(parsed)) values[key] = parsed;
+ if (self.idGenerator === 'increment') {
+ var parsed = parseInt(val, 10);
+ if (!isNaN(parsed)) values[key] = parsed;
+ }
});
callback(null, values);
}
@@ -137,11 +139,12 @@ exports.find = function find(searches, callback) {
}
}
if (sets.length === 0 && zsetKeys.length === 0) {
+ // no specific searches, retrieve all ids
this.getClient().smembers(Nohm.prefix.idsets + this.modelName, function (err, ids) {
- if (Array.isArray(ids)) {
- /*ids = ids.map(function (val) {
- return parseInt(val.toString(), 10);
- });*/
+ if (self.idGenerator === 'increment' && Array.isArray(ids)) {
+ ids = ids.map(function (val) {
+ return parseInt(val, 10);
+ });
}
returnFunction(err, ids);
});
@@ -151,10 +154,10 @@ exports.find = function find(searches, callback) {
getZSets(returnFunction);
} else {
getSets(function (err, setids) {
- if (Array.isArray(setids)) {
- /*setids = setids.map(function (val) {
+ if (self.idGenerator === 'increment' && Array.isArray(setids)) {
+ setids = setids.map(function (val) {
return parseInt(val.toString(), 10);
- });*/
+ });
}
getZSets(function (err2, zsetids) {
if (err2) {
View
@@ -136,7 +136,7 @@ exports.idIntersection = function (t) {
testIntersection(
[arr6, arr7],
- [28,39]
+ ['hurgelwurz',28,39]
);
testIntersection(
@@ -692,7 +692,6 @@ exports.defaultIdGeneration = function (t) {t.expect(3);
test1.save(function (err) {
t.ok(!err, 'There was an error while saving.');
t.same(typeof(test1.id), 'string', 'The generated id was not a string');
- console.dir(test1.id);
t.done();
});
}

0 comments on commit 76403b3

Please sign in to comment.