Fix coercion from ObjectID to String
This commit is contained in:
parent
72897c9f1a
commit
eb6fa410fe
|
@ -1135,12 +1135,7 @@ DataAccessObject._coerce = function (where) {
|
||||||
}
|
}
|
||||||
// Check there is an operator
|
// Check there is an operator
|
||||||
var operator = null;
|
var operator = null;
|
||||||
if ('object' === typeof val) {
|
if (val.constructor === Object) {
|
||||||
if (Object.keys(val).length !== 1) {
|
|
||||||
// Skip if there are not only one properties
|
|
||||||
// as the assumption for operators is not true here
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (var op in operators) {
|
for (var op in operators) {
|
||||||
if (op in val) {
|
if (op in val) {
|
||||||
val = val[op];
|
val = val[op];
|
||||||
|
@ -1182,7 +1177,7 @@ DataAccessObject._coerce = function (where) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (val !== null && val !== undefined) {
|
if (val != null) {
|
||||||
val = DataType(val);
|
val = DataType(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1269,6 +1269,18 @@ describe('DataAccessObject', function () {
|
||||||
assert.deepEqual(where, {id: '1'});
|
assert.deepEqual(where, {id: '1'});
|
||||||
where = model._coerce({id: '1'});
|
where = model._coerce({id: '1'});
|
||||||
assert.deepEqual(where, {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 () {
|
it('should be able to coerce where clause for number types', function () {
|
||||||
|
|
Loading…
Reference in New Issue