diff --git a/lib/document.js b/lib/document.js index 498235955f..f7c83bceff 100644 --- a/lib/document.js +++ b/lib/document.js @@ -1668,7 +1668,7 @@ Document.prototype.$__path = function(path) { if (adhocType) { return adhocType; } - return this.schema.path(path); + return this.$__schema.path(path); }; /** @@ -3047,7 +3047,9 @@ Document.prototype.$__setSchema = function(schema) { for (const key of Object.keys(schema.virtuals)) { schema.virtuals[key]._applyDefaultGetters(); } - this.schema = schema; + if (schema.path('schema') == null) { + this.schema = schema; + } this.$__schema = schema; this[documentSchemaSymbol] = schema; };