File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -3702,8 +3702,9 @@ Model.castObject = function castObject(obj, options) {
3702
3702
Model . castObject . call ( schemaType . caster , val )
3703
3703
] ;
3704
3704
}
3705
+
3706
+ continue ;
3705
3707
}
3706
- continue ;
3707
3708
}
3708
3709
if ( schemaType . $isSingleNested || schemaType . $isMongooseDocumentArrayElement ) {
3709
3710
try {
Original file line number Diff line number Diff line change @@ -7796,6 +7796,29 @@ describe('Model', function() {
7796
7796
const obj = { sampleArray : { name : 'Taco' } } ;
7797
7797
assert . throws ( ( ) => Test . castObject ( obj ) , / T r i e d t o s e t n e s t e d o b j e c t f i e l d ` s a m p l e A r r a y ` t o p r i m i t i v e v a l u e / ) ;
7798
7798
} ) ;
7799
+ it ( 'handles document arrays (gh-15164)' , function ( ) {
7800
+ const barSchema = new mongoose . Schema ( {
7801
+ foo : {
7802
+ type : mongoose . Schema . Types . String ,
7803
+ required : true
7804
+ }
7805
+ } , { _id : false } ) ;
7806
+
7807
+ const fooSchema = new mongoose . Schema ( {
7808
+ bars : {
7809
+ type : [ barSchema ] ,
7810
+ required : true
7811
+ }
7812
+ } ) ;
7813
+
7814
+ const Test = db . model ( 'Test' , fooSchema ) ;
7815
+
7816
+ let obj = Test . castObject ( { bars : [ ] } ) ;
7817
+ assert . deepStrictEqual ( obj . bars , [ ] ) ;
7818
+
7819
+ obj = Test . castObject ( { bars : [ { foo : 'bar' } ] } ) ;
7820
+ assert . deepStrictEqual ( obj . bars , [ { foo : 'bar' } ] ) ;
7821
+ } ) ;
7799
7822
} ) ;
7800
7823
7801
7824
it ( 'works if passing class that extends Document to `loadClass()` (gh-12254)' , async function ( ) {
You can’t perform that action at this time.
0 commit comments