Skip to content

Commit

Permalink
fix(update): use discriminator schema to cast update if discriminator…
Browse files Browse the repository at this point in the history
… key specified in filter

Fix #7843
  • Loading branch information
vkarpov15 committed Jun 11, 2019
1 parent 51cc5a5 commit fdfe3bc
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -4333,7 +4333,20 @@ Query.prototype._castUpdate = function _castUpdate(obj, overwrite) {
useNestedStrict = this.options.useNestedStrict;
}

return castUpdate(this.schema, obj, {
let schema = this.schema;
const filter = this._conditions;
if (schema != null &&
utils.hasUserDefinedProperty(filter, schema.options.discriminatorKey) &&
typeof filter[schema.options.discriminatorKey] !== 'object' &&
schema.discriminators != null) {
const discriminatorValue = filter[schema.options.discriminatorKey];
const byValue = helpers.getDiscriminatorByValue(this.model, discriminatorValue);
schema = schema.discriminators[discriminatorValue] ||
(byValue && byValue.schema) ||
schema;
}

return castUpdate(schema, obj, {
overwrite: overwrite,
strict: strict,
omitUndefined,
Expand Down

0 comments on commit fdfe3bc

Please sign in to comment.