Skip to content

Commit c40b313

Browse files
committed
test(query): repro #5737
1 parent 2adf1f3 commit c40b313

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/model.populate.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,6 +3287,36 @@ describe('model: populate:', function() {
32873287
});
32883288
});
32893289

3290+
it('populate + slice (gh-5737a)', function(done) {
3291+
var BlogPost = db.model('gh5737b', new Schema({
3292+
title: String,
3293+
user: { type: ObjectId, ref: 'gh5737a' },
3294+
fans: [{ type: ObjectId}]
3295+
}));
3296+
var User = db.model('gh5737a', new Schema({ name: String }));
3297+
3298+
User.create([{ name: 'Fan 1' }], function(error, fans) {
3299+
assert.ifError(error);
3300+
var posts = [
3301+
{ title: 'Test 1', user: fans[0]._id, fans: [fans[0]._id] }
3302+
];
3303+
BlogPost.create(posts, function(error) {
3304+
assert.ifError(error);
3305+
BlogPost.
3306+
find({}).
3307+
slice('fans', [0, 2]).
3308+
populate('user').
3309+
exec(function(err, blogposts) {
3310+
assert.ifError(error);
3311+
3312+
assert.equal(blogposts[0].user.name, 'Fan 1');
3313+
assert.equal(blogposts[0].title, 'Test 1');
3314+
done();
3315+
});
3316+
});
3317+
});
3318+
});
3319+
32903320
it('maps results back to correct document (gh-1444)', function(done) {
32913321
var articleSchema = new Schema({
32923322
body: String,

0 commit comments

Comments
 (0)