File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -3388,7 +3388,7 @@ Document.prototype.$getAllSubdocs = function() {
3388
3388
} , seed ) ;
3389
3389
} else if ( val && ! Array . isArray ( val ) && val . $isSingleNested ) {
3390
3390
seed = Object . keys ( val . _doc ) . reduce ( function ( seed , path ) {
3391
- return docReducer ( val . _doc , seed , path ) ;
3391
+ return docReducer ( val , seed , path ) ;
3392
3392
} , seed ) ;
3393
3393
seed . push ( val ) ;
3394
3394
} else if ( val && utils . isMongooseDocumentArray ( val ) ) {
Original file line number Diff line number Diff line change @@ -11473,4 +11473,38 @@ describe('document', function() {
11473
11473
baz2 . bar = bar2 ;
11474
11474
assert . ok ( baz . populated ( 'bar' ) ) ;
11475
11475
} ) ;
11476
+
11477
+ it ( '$getAllSubdocs gets document arrays underneath a nested path (gh-11917)' , function ( ) {
11478
+ const nestedSettingsSchema = new Schema ( {
11479
+ value : String ,
11480
+ active : Boolean
11481
+ } ) ;
11482
+
11483
+ const userSettingsSchema = new Schema ( {
11484
+ nestedSettings : {
11485
+ settingsProps : [ nestedSettingsSchema ]
11486
+ }
11487
+ } ) ;
11488
+
11489
+ const userSchema = new Schema ( {
11490
+ first_name : String ,
11491
+ last_name : String ,
11492
+ settings : userSettingsSchema
11493
+ } ) ;
11494
+
11495
+ const User = db . model ( 'User' , userSchema ) ;
11496
+
11497
+ const doc = new User ( {
11498
+ settings : {
11499
+ nestedSettings : {
11500
+ settingsProps : [ { value : 'test' , active : true } ]
11501
+ }
11502
+ }
11503
+ } ) ;
11504
+
11505
+ const subdocs = doc . $getAllSubdocs ( ) ;
11506
+ assert . equal ( subdocs . length , 2 ) ;
11507
+ assert . equal ( subdocs [ 0 ] . value , 'test' ) ;
11508
+ assert . ok ( subdocs [ 1 ] . nestedSettings ) ;
11509
+ } ) ;
11476
11510
} ) ;
You can’t perform that action at this time.
0 commit comments