Skip to content

Commit

Permalink
Repro #1934
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Mar 23, 2015
1 parent 8cdd7c2 commit 9c64595
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/model.populate.test.js
Expand Up @@ -2670,4 +2670,33 @@ describe('model: populate:', function(){
});
});
});

it('handles slice (gh-1934)', function(done) {
var db = start();

var movieSchema = new Schema({ title: String, actors: [String] });
var categorySchema = new Schema({ movies: [{ type: ObjectId, ref: 'gh-1934-1' }] });

var Movie = db.model('gh-1934-1', movieSchema);
var Category = db.model('gh-1934-2', categorySchema);
var movies = [
{ title: 'Rush', actors: ['Chris Hemsworth', 'Daniel Bruhl'] },
{ title: 'Pacific Rim', actors: ['Charlie Hunnam', 'Idris Elba'] },
{ title: 'Man of Steel', actors: ['Henry Cavill', 'Amy Adams'] }
];
Movie.create(movies, function(error, m1, m2, m3) {
assert.ifError(error);
Category.create({ movies: [m1._id, m2._id, m3._id] }, function(error) {
assert.ifError(error);
Category.findOne({}).populate({ path: 'movies', options: { slice: { actors: 1 } } }).exec(function(error, category) {
assert.ifError(error);
assert.equal(category.movies.length, 3);
assert.equal(category.movies[0].actors.length, 1);
assert.equal(category.movies[1].actors.length, 1);
assert.equal(category.movies[2].actors.length, 1);
done();
});
});
});
});
});

0 comments on commit 9c64595

Please sign in to comment.