Skip to content

Commit

Permalink
fix(update): handle embedded discriminator paths when discriminator k…
Browse files Browse the repository at this point in the history
…ey is defined in the update

Fix #8378
  • Loading branch information
vkarpov15 committed Dec 5, 2019
1 parent 5cdfa4a commit 4df0a3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/helpers/query/castUpdate.js
Expand Up @@ -249,7 +249,8 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) {

let pathDetails = schema._getPathType(checkPath);

// If no schema type, check for embedded discriminators
// If no schema type, check for embedded discriminators because the
// filter or update may imply an embedded discriminator type. See #8378
if (schematype == null) {
const _res = getEmbeddedDiscriminatorPath(schema, obj, filter, checkPath);
if (_res.schematype != null) {
Expand Down
4 changes: 4 additions & 0 deletions lib/helpers/query/getEmbeddedDiscriminatorPath.js
Expand Up @@ -45,6 +45,10 @@ module.exports = function getEmbeddedDiscriminatorPath(schema, update, filter, p
discriminatorKey = filter[wrapperPath].$elemMatch[key];
}

if (discriminatorValuePath in update) {
discriminatorKey = update[discriminatorValuePath];
}

if (discriminatorKey == null || discriminators[discriminatorKey] == null) {
continue;
}
Expand Down

0 comments on commit 4df0a3c

Please sign in to comment.