From 37916168834265b73686bd990e63a3fb828cdbb9 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 28 Apr 2021 21:53:31 -0400 Subject: [PATCH] test(document): repro #10148 --- test/document.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/document.test.js b/test/document.test.js index 39acebd1757..4221a972ccc 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -9911,6 +9911,30 @@ describe('document', function() { }); }); + it('with virtual populate (gh-10148)', function() { + const childSchema = Schema({ name: String, parentId: 'ObjectId' }); + childSchema.virtual('parent', { + ref: 'Parent', + localField: 'parentId', + foreignField: '_id', + justOne: true + }); + const Child = db.model('Child', childSchema); + + const Parent = db.model('Parent', Schema({ name: String })); + + return co(function*() { + const p = yield Parent.create({ name: 'Anakin' }); + yield Child.create({ name: 'Luke', parentId: p._id }); + + const res = yield Child.findOne().populate('parent'); + assert.equal(res.parent.name, 'Anakin'); + const docs = res.$getPopulatedDocs(); + assert.equal(docs.length, 1); + assert.equal(docs[0].name, 'Anakin'); + }); + }); + it('handles paths named `db` (gh-9798)', function() { const schema = new Schema({ db: String