Merge pull request #652 from strongloop/feature/fix-objectid-coercion
Fix coercion from ObjectID to String
This commit is contained in:
commit
50ac143cea
|
@ -1139,12 +1139,7 @@ DataAccessObject._coerce = function (where) {
|
|||
}
|
||||
// Check there is an operator
|
||||
var operator = null;
|
||||
if ('object' === typeof val) {
|
||||
if (Object.keys(val).length !== 1) {
|
||||
// Skip if there are not only one properties
|
||||
// as the assumption for operators is not true here
|
||||
continue;
|
||||
}
|
||||
if (val.constructor === Object) {
|
||||
for (var op in operators) {
|
||||
if (op in val) {
|
||||
val = val[op];
|
||||
|
@ -1186,7 +1181,7 @@ DataAccessObject._coerce = function (where) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (val !== null && val !== undefined) {
|
||||
if (val != null) {
|
||||
val = DataType(val);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1269,6 +1269,18 @@ describe('DataAccessObject', function () {
|
|||
assert.deepEqual(where, {id: '1'});
|
||||
where = model._coerce({id: '1'});
|
||||
assert.deepEqual(where, {id: '1'});
|
||||
|
||||
// Mockup MongoDB ObjectID
|
||||
function ObjectID(id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
ObjectID.prototype.toString = function() {
|
||||
return this.id;
|
||||
};
|
||||
|
||||
where = model._coerce({id: new ObjectID('1')});
|
||||
assert.deepEqual(where, {id: '1'});
|
||||
});
|
||||
|
||||
it('should be able to coerce where clause for number types', function () {
|
||||
|
|
Loading…
Reference in New Issue