Skip to content

Commit

Permalink
Merge branch '3.8.x'
Browse files Browse the repository at this point in the history
Conflicts:
	package.json
  • Loading branch information
vkarpov15 committed Mar 24, 2015
2 parents 1624116 + 5a4e6fd commit 0ffbf77
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -15,7 +15,7 @@
"mpath": "0.1.1",
"kareem": "1.0.0",
"regexp-clone": "0.0.1",
"mquery" : "1.0.0",
"mquery" : "1.4.0",
"async": "0.9.0"
},
"devDependencies": {
Expand Down
29 changes: 29 additions & 0 deletions test/model.populate.test.js
Expand Up @@ -2836,4 +2836,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 0ffbf77

Please sign in to comment.