File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments