File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -8345,6 +8345,31 @@ describe('model: populate:', function() {
8345
8345
} ) ;
8346
8346
} ) ;
8347
8347
8348
+ it ( 'sets populate virtual to empty array if local field empty (gh-8230)' , function ( ) {
8349
+ const GroupSchema = new Schema ( {
8350
+ roles : [ {
8351
+ roleId : String
8352
+ } ]
8353
+ } ) ;
8354
+ GroupSchema . virtual ( 'roles$' , {
8355
+ ref : 'gh8230_Role' ,
8356
+ localField : 'roles.roleId' ,
8357
+ foreignField : '_id'
8358
+ } ) ;
8359
+
8360
+ const RoleSchema = new Schema ( { } ) ;
8361
+
8362
+ const GroupModel = db . model ( 'gh8230_Group' , GroupSchema ) ;
8363
+ db . model ( 'gh8230_Role' , RoleSchema ) ;
8364
+
8365
+ return co ( function * ( ) {
8366
+ yield GroupModel . create ( { roles : [ ] } ) ;
8367
+
8368
+ const res = yield GroupModel . findOne ( { } ) . populate ( 'roles$' ) ;
8369
+ assert . deepEqual ( res . roles$ , [ ] ) ;
8370
+ } ) ;
8371
+ } ) ;
8372
+
8348
8373
it ( 'sets populate virtual with count to 0 if local field empty (gh-7731)' , function ( ) {
8349
8374
const GroupSchema = new Schema ( {
8350
8375
roles : [ {
You can’t perform that action at this time.
0 commit comments