Skip to content

Commit

Permalink
fix: handle changing discrim key on nested ops
Browse files Browse the repository at this point in the history
  • Loading branch information
IslandRhythms committed Oct 5, 2023
1 parent 8838dfc commit 0dbf92d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/cast.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ 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);
}
for (let k = 0; k < val.length; ++k) {
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)

Check failure on line 72 in lib/cast.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Missing semicolon

Check failure on line 73 in lib/cast.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Trailing spaces not allowed
// val[k] = cast(schema, val[k], options, context);
}
} else if (path === '$where') {
type = typeof val;
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
1 change: 0 additions & 1 deletion lib/schematype.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 0dbf92d

Please sign in to comment.