Skip to content

Commit

Permalink
test(populate): repro #6988
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Sep 13, 2018
1 parent a01b827 commit 0bff408
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/model.populate.test.js
Expand Up @@ -7610,4 +7610,34 @@ describe('model: populate:', function() {
'file1.png');
});
});

it('handles virtual justOne if it is not set (gh-6988)', function() {
const postSchema = new Schema({
name: String
});

postSchema.virtual('comments', {
ref: 'gh6988_Comment',
localField: '_id',
foreignField: 'postId'
});

const commentSchema = new Schema({
postId: { type: Schema.Types.ObjectId }
});

const Post = db.model('gh6988_Post', postSchema);
const Comment = db.model('gh6988_Comment', commentSchema);

return co(function*() {
const post = yield Post.create({ name: 'n1'});
const comment = yield Comment.create({ postId: post._id });

const doc = yield Post.findOne({}).populate('comments').lean();
assert.ok(Array.isArray(doc.comments));
assert.equal(doc.comments.length, 1);
assert.equal(doc.comments[0]._id.toHexString(),
comment._id.toHexString());
});
});
});

0 comments on commit 0bff408

Please sign in to comment.