@@ -741,7 +741,7 @@ function init(self, obj, doc, opts, prefix) {
741
741
if ( i === '__proto__' || i === 'constructor' ) {
742
742
return ;
743
743
}
744
- path = prefix + i ;
744
+ path = prefix ? prefix + i : i ;
745
745
schemaType = docSchema . path ( path ) ;
746
746
747
747
// Should still work if not a model-level discriminator, but should not be
@@ -751,38 +751,39 @@ function init(self, obj, doc, opts, prefix) {
751
751
return ;
752
752
}
753
753
754
- if ( ! schemaType && utils . isPOJO ( obj [ i ] ) ) {
754
+ const value = obj [ i ] ;
755
+ if ( ! schemaType && utils . isPOJO ( value ) ) {
755
756
// assume nested object
756
757
if ( ! doc [ i ] ) {
757
758
doc [ i ] = { } ;
758
759
if ( ! strict && ! ( i in docSchema . tree ) && ! ( i in docSchema . methods ) && ! ( i in docSchema . virtuals ) ) {
759
760
self [ i ] = doc [ i ] ;
760
761
}
761
762
}
762
- init ( self , obj [ i ] , doc [ i ] , opts , path + '.' ) ;
763
+ init ( self , value , doc [ i ] , opts , path + '.' ) ;
763
764
} else if ( ! schemaType ) {
764
- doc [ i ] = obj [ i ] ;
765
+ doc [ i ] = value ;
765
766
if ( ! strict && ! prefix ) {
766
- self [ i ] = obj [ i ] ;
767
+ self [ i ] = value ;
767
768
}
768
769
} else {
769
770
// Retain order when overwriting defaults
770
- if ( doc . hasOwnProperty ( i ) && obj [ i ] !== void 0 ) {
771
+ if ( doc . hasOwnProperty ( i ) && value !== void 0 ) {
771
772
delete doc [ i ] ;
772
773
}
773
- if ( obj [ i ] === null ) {
774
+ if ( value === null ) {
774
775
doc [ i ] = schemaType . _castNullish ( null ) ;
775
- } else if ( obj [ i ] !== undefined ) {
776
- const wasPopulated = obj [ i ] . $__ == null ? null : obj [ i ] . $__ . wasPopulated ;
776
+ } else if ( value !== undefined ) {
777
+ const wasPopulated = value . $__ == null ? null : value . $__ . wasPopulated ;
777
778
778
779
if ( schemaType && ! wasPopulated ) {
779
780
try {
780
781
if ( opts && opts . setters ) {
781
782
// Call applySetters with `init = false` because otherwise setters are a noop
782
783
const overrideInit = false ;
783
- doc [ i ] = schemaType . applySetters ( obj [ i ] , self , overrideInit ) ;
784
+ doc [ i ] = schemaType . applySetters ( value , self , overrideInit ) ;
784
785
} else {
785
- doc [ i ] = schemaType . cast ( obj [ i ] , self , true ) ;
786
+ doc [ i ] = schemaType . cast ( value , self , true ) ;
786
787
}
787
788
} catch ( e ) {
788
789
self . invalidate ( e . path , new ValidatorError ( {
@@ -794,7 +795,7 @@ function init(self, obj, doc, opts, prefix) {
794
795
} ) ) ;
795
796
}
796
797
} else {
797
- doc [ i ] = obj [ i ] ;
798
+ doc [ i ] = value ;
798
799
}
799
800
}
800
801
// mark as hydrated
0 commit comments