Skip to content

Commit

Permalink
fix(document): run setter only once when doing .set() underneath a …
Browse files Browse the repository at this point in the history
…single nested subdoc

Fix #7196
  • Loading branch information
vkarpov15 committed Nov 2, 2018
1 parent 10837d4 commit 751397c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/document.js
Expand Up @@ -980,10 +980,16 @@ Document.prototype.$set = function $set(path, val, type, options) {
didPopulate = true;
}

const setterContext = constructing && this.$__.$options.priorDoc ?
this.$__.$options.priorDoc :
this;
val = schema.applySetters(val, setterContext, false, priorVal);
// If this path is underneath a single nested schema, we'll call the setter
// later in `$__set()` because we don't take `_doc` when we iterate through
// a single nested doc. That's to make sure we get the correct context.
// Otherwise we would double-call the setter, see gh-7196.
if (this.schema.singleNestedPaths[path] == null) {
const setterContext = constructing && this.$__.$options.priorDoc ?
this.$__.$options.priorDoc :
this;
val = schema.applySetters(val, setterContext, false, priorVal);
}

if (!didPopulate && this.$__.populated) {
delete this.$__.populated[path];
Expand Down

0 comments on commit 751397c

Please sign in to comment.