Skip to content

Commit

Permalink
Fix getAll bug when the model uses increment as idGenerator and the f…
Browse files Browse the repository at this point in the history
…oreign model does not.
  • Loading branch information
maritz committed Dec 4, 2012
1 parent 47e5bb6 commit b853a28
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/relations.js
Expand Up @@ -53,8 +53,9 @@ exports.getAll = function getAll(objName, name) {
value = []; value = [];
} else { } else {
value = value.map(function (val) { value = value.map(function (val) {
if (self.idGenerator === 'increment') { var int_val = parseInt(val.toString(), 10);
val = parseInt(val.toString(), 10); if (!isNaN(int_val) && int_val == val) {
val = int_val;
} }
return val; return val;
}); });
Expand Down
24 changes: 24 additions & 0 deletions test/relationTests.js
Expand Up @@ -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) { numLinks: function (t) {
var user = new UserLinkMockup(), var user = new UserLinkMockup(),
role = new RoleLinkMockup(), role = new RoleLinkMockup(),
Expand Down

0 comments on commit b853a28

Please sign in to comment.