Skip to content

Commit 75150ca

Browse files
committed
test(populate): repro #7848
1 parent 6133770 commit 75150ca

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/model.populate.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8394,4 +8394,32 @@ describe('model: populate:', function() {
83948394
assert.strictEqual(doc.list[0].fill.child.name, 'test');
83958395
});
83968396
});
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+
});
83978425
});

0 commit comments

Comments
 (0)