@@ -1572,7 +1572,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
15721572 let name ;
15731573
15741574 if ( utils . isPOJO ( type ) || type === 'mixed' ) {
1575- return new MongooseTypes . Mixed ( path , obj ) ;
1575+ return new MongooseTypes . Mixed ( path , obj , null , this ) ;
15761576 }
15771577
15781578 if ( Array . isArray ( type ) || type === Array || type === 'array' || type === MongooseTypes . Array ) {
@@ -1595,7 +1595,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
15951595 `${ path } : new Schema(...)` ) ;
15961596 }
15971597 }
1598- return new MongooseTypes . DocumentArray ( path , cast , obj ) ;
1598+ return new MongooseTypes . DocumentArray ( path , cast , obj , null , this ) ;
15991599 }
16001600 if ( cast &&
16011601 cast [ options . typeKey ] &&
@@ -1612,14 +1612,14 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
16121612 `${ path } : new Schema(...)` ) ;
16131613 }
16141614 }
1615- return new MongooseTypes . DocumentArray ( path , cast [ options . typeKey ] , obj , cast ) ;
1615+ return new MongooseTypes . DocumentArray ( path , cast [ options . typeKey ] , obj , cast , this ) ;
16161616 }
16171617 if ( typeof cast !== 'undefined' ) {
16181618 if ( Array . isArray ( cast ) || cast . type === Array || cast . type == 'Array' ) {
16191619 if ( cast && cast . type == 'Array' ) {
16201620 cast . type = Array ;
16211621 }
1622- return new MongooseTypes . Array ( path , this . interpretAsType ( path , cast , options ) , obj ) ;
1622+ return new MongooseTypes . Array ( path , this . interpretAsType ( path , cast , options ) , obj , null , this ) ;
16231623 }
16241624 }
16251625
@@ -1660,10 +1660,10 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
16601660
16611661 const childSchema = new Schema ( castFromTypeKey , childSchemaOptions ) ;
16621662 childSchema . $implicitlyCreated = true ;
1663- return new MongooseTypes . DocumentArray ( path , childSchema , obj ) ;
1663+ return new MongooseTypes . DocumentArray ( path , childSchema , obj , null , this ) ;
16641664 } else {
16651665 // Special case: empty object becomes mixed
1666- return new MongooseTypes . Array ( path , MongooseTypes . Mixed , obj ) ;
1666+ return new MongooseTypes . Array ( path , MongooseTypes . Mixed , obj , null , this ) ;
16671667 }
16681668 }
16691669
@@ -1672,7 +1672,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
16721672 ? cast [ options . typeKey ]
16731673 : cast ;
16741674 if ( Array . isArray ( type ) ) {
1675- return new MongooseTypes . Array ( path , this . interpretAsType ( path , type , options ) , obj ) ;
1675+ return new MongooseTypes . Array ( path , this . interpretAsType ( path , type , options ) , obj , null , this ) ;
16761676 }
16771677
16781678 name = typeof type === 'string'
@@ -1700,11 +1700,11 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
17001700 }
17011701 }
17021702
1703- return new MongooseTypes . Array ( path , cast || MongooseTypes . Mixed , obj , options ) ;
1703+ return new MongooseTypes . Array ( path , cast || MongooseTypes . Mixed , obj , options , this ) ;
17041704 }
17051705
17061706 if ( type && type . instanceOfSchema ) {
1707- return new MongooseTypes . Subdocument ( type , path , obj ) ;
1707+ return new MongooseTypes . Subdocument ( type , path , obj , this ) ;
17081708 }
17091709
17101710 if ( Buffer . isBuffer ( type ) ) {
@@ -1743,53 +1743,11 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
17431743 'https://bit.ly/mongoose-schematypes for a list of valid schema types.' ) ;
17441744 }
17451745
1746- if ( name === 'Union' ) {
1747- obj . parentSchema = this ;
1748- }
1749- const schemaType = new MongooseTypes [ name ] ( path , obj , options ) ;
1750-
1751- if ( schemaType . $isSchemaMap ) {
1752- createMapNestedSchemaType ( this , schemaType , path , obj , options ) ;
1753- }
1746+ const schemaType = new MongooseTypes [ name ] ( path , obj , options , this ) ;
17541747
17551748 return schemaType ;
17561749} ;
17571750
1758- /*!
1759- * ignore
1760- */
1761-
1762- function createMapNestedSchemaType ( schema , schemaType , path , obj , options ) {
1763- const mapPath = path + '.$*' ;
1764- let _mapType = { type : { } } ;
1765- if ( utils . hasUserDefinedProperty ( obj , 'of' ) ) {
1766- const isInlineSchema = utils . isPOJO ( obj . of ) &&
1767- Object . keys ( obj . of ) . length > 0 &&
1768- ! utils . hasUserDefinedProperty ( obj . of , schema . options . typeKey ) ;
1769- if ( isInlineSchema ) {
1770- _mapType = { [ schema . options . typeKey ] : new Schema ( obj . of ) } ;
1771- } else if ( utils . isPOJO ( obj . of ) ) {
1772- _mapType = Object . assign ( { } , obj . of ) ;
1773- } else {
1774- _mapType = { [ schema . options . typeKey ] : obj . of } ;
1775- }
1776-
1777- if ( _mapType [ schema . options . typeKey ] && _mapType [ schema . options . typeKey ] . instanceOfSchema ) {
1778- const subdocumentSchema = _mapType [ schema . options . typeKey ] ;
1779- subdocumentSchema . eachPath ( ( subpath , type ) => {
1780- if ( type . options . select === true || type . options . select === false ) {
1781- throw new MongooseError ( 'Cannot use schema-level projections (`select: true` or `select: false`) within maps at path "' + path + '.' + subpath + '"' ) ;
1782- }
1783- } ) ;
1784- }
1785-
1786- if ( utils . hasUserDefinedProperty ( obj , 'ref' ) ) {
1787- _mapType . ref = obj . ref ;
1788- }
1789- }
1790- schemaType . $__schemaType = schema . interpretAsType ( mapPath , _mapType , options ) ;
1791- }
1792-
17931751/**
17941752 * Iterates the schemas paths similar to Array#forEach.
17951753 *
0 commit comments