Skip to content

Commit 0dbf92d

Browse files
committed
fix: handle changing discrim key on nested ops
1 parent 8838dfc commit 0dbf92d

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

lib/cast.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ module.exports = function cast(schema, obj, options, context) {
6161
val = obj[path];
6262

6363
if (path === '$or' || path === '$nor' || path === '$and') {
64-
console.log('what is val', val);
6564
if (!Array.isArray(val)) {
6665
throw new CastError('Array', val, path);
6766
}
6867
for (let k = 0; k < val.length; ++k) {
6968
if (val[k] == null || typeof val[k] !== 'object') {
7069
throw new CastError('Object', val[k], path + '.' + k);
7170
}
72-
val[k] = cast(schema, val[k], options, context);
71+
const discrim = getSchemaDiscriminatorByValue(context.schema, val[k][schema.options.discriminatorKey]);
72+
val[k] = cast(discrim ? discrim : schema, val[k], options, context)
73+
74+
// val[k] = cast(schema, val[k], options, context);
7375
}
7476
} else if (path === '$where') {
7577
type = typeof val;
@@ -367,8 +369,6 @@ module.exports = function cast(schema, obj, options, context) {
367369

368370
obj[path] = { $in: casted };
369371
} else {
370-
console.log('Houston we have a problem.');
371-
console.log('what is obj[path]', obj[path], path, obj, val);
372372
obj[path] = schematype.castForQuery(
373373
null,
374374
val,

lib/query.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4889,7 +4889,6 @@ function _getPopulatedPaths(list, arr, prefix) {
48894889

48904890
Query.prototype.cast = function(model, obj) {
48914891
obj || (obj = this._conditions);
4892-
48934892
model = model || this.model;
48944893
const discriminatorKey = model.schema.options.discriminatorKey;
48954894
if (obj != null &&

lib/schematype.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,6 @@ SchemaType.prototype._applySetters = function(value, scope, init, priorVal, opti
11861186
const setters = this.setters;
11871187

11881188
for (let i = setters.length - 1; i >= 0; i--) {
1189-
console.log('what is v', v, setters.length);
11901189
v = setters[i].call(scope, v, priorVal, this, options);
11911190
}
11921191

0 commit comments

Comments
 (0)