diff --git a/lib/document.js b/lib/document.js index b91627899e1..78621707a2c 100644 --- a/lib/document.js +++ b/lib/document.js @@ -726,7 +726,6 @@ Document.prototype.$init = function() { Document.prototype.$__init = function(doc, opts) { this.$isNew = false; - this.$init = true; opts = opts || {}; // handle docs with populated paths @@ -988,8 +987,11 @@ Document.prototype.$session = function $session(session) { 'called `endSession()` on the session you are passing to `$session()`.'); } - this.$__.session = session; + if (session == null && this.$__.session == null) { + return; + } + this.$__.session = session; if (!this.$isSubdocument) { const subdocs = this.$getAllSubdocs(); diff --git a/lib/internal.js b/lib/internal.js index 7e534dc994f..beab97fc5aa 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -11,12 +11,10 @@ module.exports = exports = InternalCache; function InternalCache() { this.activePaths = new ActiveRoster; - - // embedded docs - this.ownerDocument = undefined; - this.fullPath = undefined; + this.strictMode = undefined; } +InternalCache.prototype.fullPath = undefined; InternalCache.prototype.strictMode = undefined; InternalCache.prototype.selected = undefined; InternalCache.prototype.shardval = undefined; @@ -28,6 +26,7 @@ InternalCache.prototype.inserting = undefined; InternalCache.prototype.saving = undefined; InternalCache.prototype.version = undefined; InternalCache.prototype._id = undefined; +InternalCache.prototype.ownerDocument = undefined; InternalCache.prototype.populate = undefined; // what we want to populate in this doc InternalCache.prototype.populated = undefined;// the _ids that have been populated InternalCache.prototype.wasPopulated = false; // if this doc was the result of a population diff --git a/lib/queryhelpers.js b/lib/queryhelpers.js index 7fdebdb6303..8b495aca8eb 100644 --- a/lib/queryhelpers.js +++ b/lib/queryhelpers.js @@ -111,16 +111,16 @@ exports.createModel = function createModel(model, doc, fields, userProvidedField return new discriminator(undefined, _fields, true); } } - if (typeof options === 'undefined') { - options = {}; - options.defaults = true; - } - return new model(undefined, fields, { + + const _opts = { skipId: true, isNew: false, - willInit: true, - defaults: options.defaults - }); + willInit: true + }; + if (options != null && 'defaults' in options) { + _opts.defaults = options.defaults; + } + return new model(undefined, fields, _opts); }; /*! diff --git a/lib/types/subdocument.js b/lib/types/subdocument.js index de686896c72..d22ed4451fd 100644 --- a/lib/types/subdocument.js +++ b/lib/types/subdocument.js @@ -19,7 +19,10 @@ module.exports = Subdocument; function Subdocument(value, fields, parent, skipId, options) { if (parent != null) { // If setting a nested path, should copy isNew from parent re: gh-7048 - const parentOptions = { isNew: parent.isNew, defaults: 'defaults' in parent.$__ ? parent.$__.defaults : true }; + const parentOptions = { isNew: parent.isNew }; + if ('defaults' in parent.$__) { + parentOptions.defaults = parent.$__.defaults; + } options = Object.assign({}, parentOptions, options); } if (options != null && options.path != null) {