File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -9000,4 +9000,36 @@ describe('model: populate:', function() {
90009000 assert . equal ( res . list [ 2 ] . data . sourceId , 123 ) ;
90019001 } ) ;
90029002 } ) ;
9003+
9004+ it ( 'excluding foreignField using minus path deselects foreignField (gh-8460)' , function ( ) {
9005+ const schema = Schema ( { specialId : String } ) ;
9006+
9007+ schema . virtual ( 'searchResult' , {
9008+ ref : 'gh8460_Result' ,
9009+ localField : 'specialId' ,
9010+ foreignField : 'specialId' ,
9011+ options : { select : 'name -_id -specialId' } ,
9012+ justOne : true
9013+ } ) ;
9014+ const Model = db . model ( 'gh8460_Model' , schema ) ;
9015+ const Result = db . model ( 'gh8460_Result' , Schema ( {
9016+ name : String ,
9017+ specialId : String ,
9018+ other : String
9019+ } ) ) ;
9020+
9021+ return co ( function * ( ) {
9022+ yield Result . create ( { name : 'foo' , specialId : 'secret' , other : 'test' } ) ;
9023+ yield Model . create ( { specialId : 'secret' } ) ;
9024+
9025+ let doc = yield Model . findOne ( ) . populate ( 'searchResult' ) ;
9026+ assert . strictEqual ( doc . searchResult . specialId , void 0 ) ;
9027+
9028+ doc = yield Model . findOne ( ) . populate ( {
9029+ path : 'searchResult' ,
9030+ select : 'name -_id'
9031+ } ) ;
9032+ assert . strictEqual ( doc . searchResult . specialId , 'secret' ) ;
9033+ } ) ;
9034+ } ) ;
90039035} ) ;
You can’t perform that action at this time.
0 commit comments