@@ -681,21 +681,9 @@ Schema.prototype.path = function(path, obj) {
681
681
// The '$' is to imply this path should never be stored in MongoDB so we
682
682
// can easily build a regexp out of this path, and '*' to imply "any key."
683
683
const mapPath = path + '.$*' ;
684
- let _mapType = { type : { } } ;
685
- if ( utils . hasUserDefinedProperty ( obj , 'of' ) ) {
686
- const isInlineSchema = utils . isPOJO ( obj . of ) &&
687
- Object . keys ( obj . of ) . length > 0 &&
688
- ! utils . hasUserDefinedProperty ( obj . of , this . options . typeKey ) ;
689
- _mapType = isInlineSchema ? new Schema ( obj . of ) : obj . of ;
690
- }
691
- if ( utils . hasUserDefinedProperty ( obj , 'ref' ) ) {
692
- _mapType = { type : _mapType , ref : obj . ref } ;
693
- }
694
684
695
- this . paths [ mapPath ] = this . interpretAsType ( mapPath ,
696
- _mapType , this . options ) ;
685
+ this . paths [ mapPath ] = schemaType . $__schemaType ;
697
686
this . mapPaths . push ( this . paths [ mapPath ] ) ;
698
- schemaType . $__schemaType = this . paths [ mapPath ] ;
699
687
}
700
688
701
689
if ( schemaType . $isSingleNested ) {
@@ -1032,9 +1020,41 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
1032
1020
'http://bit.ly/mongoose-schematypes for a list of valid schema types.' ) ;
1033
1021
}
1034
1022
1035
- return new MongooseTypes [ name ] ( path , obj ) ;
1023
+ const schemaType = new MongooseTypes [ name ] ( path , obj ) ;
1024
+
1025
+ if ( schemaType . $isSchemaMap ) {
1026
+ createMapNestedSchemaType ( this , schemaType , path , obj , options ) ;
1027
+ }
1028
+
1029
+ return schemaType ;
1036
1030
} ;
1037
1031
1032
+ /*!
1033
+ * ignore
1034
+ */
1035
+
1036
+ function createMapNestedSchemaType ( schema , schemaType , path , obj , options ) {
1037
+ const mapPath = path + '.$*' ;
1038
+ let _mapType = { type : { } } ;
1039
+ if ( utils . hasUserDefinedProperty ( obj , 'of' ) ) {
1040
+ const isInlineSchema = utils . isPOJO ( obj . of ) &&
1041
+ Object . keys ( obj . of ) . length > 0 &&
1042
+ ! utils . hasUserDefinedProperty ( obj . of , schema . options . typeKey ) ;
1043
+ if ( isInlineSchema ) {
1044
+ _mapType = { [ schema . options . typeKey ] : new Schema ( obj . of ) } ;
1045
+ } else if ( utils . isPOJO ( obj . of ) ) {
1046
+ _mapType = Object . assign ( { } , obj . of ) ;
1047
+ } else {
1048
+ _mapType = { [ schema . options . typeKey ] : obj . of } ;
1049
+ }
1050
+
1051
+ if ( utils . hasUserDefinedProperty ( obj , 'ref' ) ) {
1052
+ _mapType . ref = obj . ref ;
1053
+ }
1054
+ }
1055
+ schemaType . $__schemaType = schema . interpretAsType ( mapPath , _mapType , options ) ;
1056
+ }
1057
+
1038
1058
/**
1039
1059
* Iterates the schemas paths similar to Array#forEach.
1040
1060
*
0 commit comments