mongoose 7.2.3 → 7.2.4
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/dist/browser.umd.js +1 -1
- package/lib/cast.js +11 -3
- package/package.json +1 -1
package/lib/cast.js
CHANGED
|
@@ -118,9 +118,17 @@ module.exports = function cast(schema, obj, options, context) {
|
|
|
118
118
|
discriminatorKey != null &&
|
|
119
119
|
pathLastHalf !== discriminatorKey) {
|
|
120
120
|
const discriminatorVal = get(obj, pathFirstHalf + '.' + discriminatorKey);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
const discriminators = _schematype.schema.discriminators;
|
|
122
|
+
if (typeof discriminatorVal === 'string' && discriminators[discriminatorVal] != null) {
|
|
123
|
+
|
|
124
|
+
schematype = discriminators[discriminatorVal].path(pathLastHalf);
|
|
125
|
+
} else if (discriminatorVal != null &&
|
|
126
|
+
Object.keys(discriminatorVal).length === 1 &&
|
|
127
|
+
Array.isArray(discriminatorVal.$in) &&
|
|
128
|
+
discriminatorVal.$in.length === 1 &&
|
|
129
|
+
typeof discriminatorVal.$in[0] === 'string' &&
|
|
130
|
+
discriminators[discriminatorVal.$in[0]] != null) {
|
|
131
|
+
schematype = discriminators[discriminatorVal.$in[0]].path(pathLastHalf);
|
|
124
132
|
}
|
|
125
133
|
}
|
|
126
134
|
}
|