Fix a regression in mongodb connector

This commit is contained in:
Raymond Feng 2013-12-15 22:51:47 -08:00
parent 8d1d6f4466
commit 1b9edbcfcb
2 changed files with 20 additions and 1 deletions

View File

@ -392,7 +392,18 @@ DataAccessObject._coerce = function (where) {
return Boolean(val); return Boolean(val);
} }
}; };
} else if(DataType === Number) {
// This fixes a regression in mongodb connector
// For numbers, only convert it produces a valid number
// LoopBack by default injects a number id. We should fix it based
// on the connector's input, for example, mongoddb should use string
// while RDBs typically use number
DataType = function(val) {
var num = Number(val);
return !isNaN(num) ? num : val;
};
} }
if (!DataType) { if (!DataType) {
continue; continue;
} }

View File

@ -662,6 +662,14 @@ describe('DataAccessObject', function () {
assert.deepEqual(where, {date: undefined}); assert.deepEqual(where, {date: undefined});
}); });
it('should skip conversion if it produces NaN for numbers', function () {
where = model._coerce({age: 'xyz'});
assert.deepEqual(where, {age: 'xyz'});
where = model._coerce({age: {inq: ['xyz', '12']}});
assert.deepEqual(where, {age: {inq: ['xyz', 12]}});
});
}); });
describe('Load models from json', function () { describe('Load models from json', function () {