From 0dbf92d08673db82f9a2684b2a5c2128a2bbe9f3 Mon Sep 17 00:00:00 2001 From: Daniel Diaz <39510674+IslandRhythms@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:13:23 -0400 Subject: [PATCH] fix: handle changing discrim key on nested ops --- lib/cast.js | 8 ++++---- lib/query.js | 1 - lib/schematype.js | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/cast.js b/lib/cast.js index 67fbbf765eb..1ed94fc711e 100644 --- a/lib/cast.js +++ b/lib/cast.js @@ -61,7 +61,6 @@ module.exports = function cast(schema, obj, options, context) { val = obj[path]; if (path === '$or' || path === '$nor' || path === '$and') { - console.log('what is val', val); if (!Array.isArray(val)) { throw new CastError('Array', val, path); } @@ -69,7 +68,10 @@ module.exports = function cast(schema, obj, options, context) { if (val[k] == null || typeof val[k] !== 'object') { throw new CastError('Object', val[k], path + '.' + k); } - val[k] = cast(schema, val[k], options, context); + const discrim = getSchemaDiscriminatorByValue(context.schema, val[k][schema.options.discriminatorKey]); + val[k] = cast(discrim ? discrim : schema, val[k], options, context) + + // val[k] = cast(schema, val[k], options, context); } } else if (path === '$where') { type = typeof val; @@ -367,8 +369,6 @@ module.exports = function cast(schema, obj, options, context) { obj[path] = { $in: casted }; } else { - console.log('Houston we have a problem.'); - console.log('what is obj[path]', obj[path], path, obj, val); obj[path] = schematype.castForQuery( null, val, diff --git a/lib/query.js b/lib/query.js index ba141649a48..7a3d00fe699 100644 --- a/lib/query.js +++ b/lib/query.js @@ -4889,7 +4889,6 @@ function _getPopulatedPaths(list, arr, prefix) { Query.prototype.cast = function(model, obj) { obj || (obj = this._conditions); - model = model || this.model; const discriminatorKey = model.schema.options.discriminatorKey; if (obj != null && diff --git a/lib/schematype.js b/lib/schematype.js index 68fd9c8ddaa..c7d27c6a467 100644 --- a/lib/schematype.js +++ b/lib/schematype.js @@ -1186,7 +1186,6 @@ SchemaType.prototype._applySetters = function(value, scope, init, priorVal, opti const setters = this.setters; for (let i = setters.length - 1; i >= 0; i--) { - console.log('what is v', v, setters.length); v = setters[i].call(scope, v, priorVal, this, options); }