Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix getAll bug when the model uses increment as idGenerator and the f…

…oreign model does not.
  • Loading branch information...
commit b853a284817c8779629f814240320b9da16b54aa 1 parent 47e5bb6
@maritz authored
Showing with 27 additions and 2 deletions.
  1. +3 −2 lib/relations.js
  2. +24 −0 test/relationTests.js
View
5 lib/relations.js
@@ -53,8 +53,9 @@ exports.getAll = function getAll(objName, name) {
value = [];
} else {
value = value.map(function (val) {
- if (self.idGenerator === 'increment') {
- val = parseInt(val.toString(), 10);
+ var int_val = parseInt(val.toString(), 10);
+ if (!isNaN(int_val) && int_val == val) {
+ val = int_val;
}
return val;
});
View
24 test/relationTests.js
@@ -326,6 +326,30 @@ exports.relation = {
});
},
+ 'getAll with different id generators': function (t) {
+ var user = new UserLinkMockup(),
+ comment = new CommentLinkMockup();
+ t.expect(1);
+
+ user.link(comment);
+
+ user.save(function (err) {
+ if (err) {
+ console.dir(err);
+ t.done();
+ }
+ var should = [comment.id];
+ user.getAll(comment.modelName, function (err, values) {
+ if (err) {
+ console.dir(err);
+ t.done();
+ }
+ t.same(values, should, 'getAll() did not return the correct array');
+ t.done();
+ });
+ });
+ },
+
numLinks: function (t) {
var user = new UserLinkMockup(),
role = new RoleLinkMockup(),
Please sign in to comment.
Something went wrong with that request. Please try again.