Skip to content

Commit

Permalink
test(query): repro #5737
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 6, 2017
1 parent 2adf1f3 commit c40b313
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/model.populate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3287,6 +3287,36 @@ describe('model: populate:', function() {
});
});

it('populate + slice (gh-5737a)', function(done) {
var BlogPost = db.model('gh5737b', new Schema({
title: String,
user: { type: ObjectId, ref: 'gh5737a' },
fans: [{ type: ObjectId}]
}));
var User = db.model('gh5737a', new Schema({ name: String }));

User.create([{ name: 'Fan 1' }], function(error, fans) {
assert.ifError(error);
var posts = [
{ title: 'Test 1', user: fans[0]._id, fans: [fans[0]._id] }
];
BlogPost.create(posts, function(error) {
assert.ifError(error);
BlogPost.
find({}).
slice('fans', [0, 2]).
populate('user').
exec(function(err, blogposts) {
assert.ifError(error);

assert.equal(blogposts[0].user.name, 'Fan 1');
assert.equal(blogposts[0].title, 'Test 1');
done();
});
});
});
});

it('maps results back to correct document (gh-1444)', function(done) {
var articleSchema = new Schema({
body: String,
Expand Down

0 comments on commit c40b313

Please sign in to comment.