Skip to content

Commit

Permalink
test(document): repro #10148
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Apr 29, 2021
1 parent 06c6a8b commit 3791616
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3791616

Please sign in to comment.