diff --git a/lib/dao.js b/lib/dao.js index 5207d4af..22f9cff2 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -392,8 +392,19 @@ DataAccessObject._coerce = function (where) { 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; } diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index bd24a623..2cebc11d 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -662,6 +662,14 @@ describe('DataAccessObject', function () { 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 () {