Skip to content

Commit ca4f52b

Browse files
committed
test(populate): repro #8230
1 parent ecd8242 commit ca4f52b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/model.populate.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8345,6 +8345,31 @@ describe('model: populate:', function() {
83458345
});
83468346
});
83478347

8348+
it('sets populate virtual to empty array if local field empty (gh-8230)', function() {
8349+
const GroupSchema = new Schema({
8350+
roles: [{
8351+
roleId: String
8352+
}]
8353+
});
8354+
GroupSchema.virtual('roles$', {
8355+
ref: 'gh8230_Role',
8356+
localField: 'roles.roleId',
8357+
foreignField: '_id'
8358+
});
8359+
8360+
const RoleSchema = new Schema({});
8361+
8362+
const GroupModel = db.model('gh8230_Group', GroupSchema);
8363+
db.model('gh8230_Role', RoleSchema);
8364+
8365+
return co(function*() {
8366+
yield GroupModel.create({ roles: [] });
8367+
8368+
const res = yield GroupModel.findOne({}).populate('roles$');
8369+
assert.deepEqual(res.roles$, []);
8370+
});
8371+
});
8372+
83488373
it('sets populate virtual with count to 0 if local field empty (gh-7731)', function() {
83498374
const GroupSchema = new Schema({
83508375
roles: [{

0 commit comments

Comments
 (0)