Skip to content

Commit

Permalink
test(populate): repro #8198
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 3, 2019
1 parent 9a1d494 commit f8db7ce
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/model.populate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8639,4 +8639,32 @@ describe('model: populate:', function() {
assert.equal(res.nested.events[0].nestedLayer.users_$[0].name, 'test');
});
});

it('accessing populate virtual prop (gh-8198)', function() {
const FooSchema = new Schema({
name: String,
children: [{
barId: { type: Schema.Types.ObjectId, ref: 'gh8198_Bar' },
quantity: Number,
}]
});
FooSchema.virtual('children.bar', {
ref: 'gh8198_Bar',
localField: 'children.barId',
foreignField: '_id',
justOne: true
});
const BarSchema = Schema({ name: String });
const Foo = db.model('gh8198_FooSchema', FooSchema);
const Bar = db.model('gh8198_Bar', BarSchema);
return co(function*() {
const bar = yield Bar.create({ name: 'bar' });
const foo = yield Foo.create({
name: 'foo',
children: [{ barId: bar._id, quantity: 1 }]
});
const foo2 = yield Foo.findById(foo._id).populate('children.bar');
assert.equal(foo2.children[0].bar.name, 'bar');
});
});
});

0 comments on commit f8db7ce

Please sign in to comment.