mongoose 9.11.3 → 9.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cast.js CHANGED
@@ -4,6 +4,7 @@
4
4
  * Module dependencies.
5
5
  */
6
6
 
7
+ const getDiscriminatorByKey = require('./helpers/discriminator/getDiscriminatorByKey');
7
8
  const CastError = require('./error/cast');
8
9
  const StrictModeError = require('./error/strict');
9
10
  const Types = require('./schema/index');
@@ -138,8 +139,9 @@ module.exports = function cast(schema, obj, options, context) {
138
139
  pathLastHalf !== discriminatorKey) {
139
140
  const discriminatorVal = getDiscriminatorValueFromFilter(get(obj, pathFirstHalf + '.' + discriminatorKey));
140
141
  const discriminators = _schematype.schema.discriminators;
141
- if (typeof discriminatorVal === 'string' && discriminators[discriminatorVal] != null) {
142
- schematype = discriminators[discriminatorVal].path(pathLastHalf);
142
+ const discriminator = typeof discriminatorVal === 'string' ? getDiscriminatorByKey(discriminators, discriminatorVal) : null;
143
+ if (discriminator != null) {
144
+ schematype = discriminator.path(pathLastHalf);
143
145
  }
144
146
  }
145
147
  }