Fix a regression in mongodb connector
This commit is contained in:
parent
8d1d6f4466
commit
1b9edbcfcb
13
lib/dao.js
13
lib/dao.js
|
@ -392,8 +392,19 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 () {
|
||||||
|
|
Loading…
Reference in New Issue