File tree 1 file changed +28
-0
lines changed 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -8394,4 +8394,32 @@ describe('model: populate:', function() {
8394
8394
assert . strictEqual ( doc . list [ 0 ] . fill . child . name , 'test' ) ;
8395
8395
} ) ;
8396
8396
} ) ;
8397
+
8398
+ it ( 'virtual refPath (gh-7848)' , function ( ) {
8399
+ const Child = db . model ( 'gh7848_Child' , Schema ( {
8400
+ name : String ,
8401
+ parentId : Number
8402
+ } ) ) ;
8403
+
8404
+ const parentSchema = Schema ( {
8405
+ _id : Number ,
8406
+ kind : String
8407
+ } ) ;
8408
+ parentSchema . virtual ( 'childDocs' , {
8409
+ refPath : 'kind' ,
8410
+ localField : '_id' ,
8411
+ foreignField : 'parentId' ,
8412
+ justOne : false
8413
+ } ) ;
8414
+ const Parent = db . model ( 'gh7848_Parent' , parentSchema ) ;
8415
+
8416
+ return co ( function * ( ) {
8417
+ yield Parent . create ( { _id : 1 , kind : 'gh7848_Child' } ) ;
8418
+ yield Child . create ( { name : 'test' , parentId : 1 } ) ;
8419
+
8420
+ const doc = yield Parent . findOne ( ) . populate ( 'childDocs' ) ;
8421
+ assert . equal ( doc . childDocs . length , 1 ) ;
8422
+ assert . equal ( doc . childDocs [ 0 ] . name , 'test' ) ;
8423
+ } ) ;
8424
+ } ) ;
8397
8425
} ) ;
You can’t perform that action at this time.
0 commit comments