File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -8667,4 +8667,27 @@ describe('model: populate:', function() {
8667
8667
assert . equal ( foo2 . children [ 0 ] . bar . name , 'bar' ) ;
8668
8668
} ) ;
8669
8669
} ) ;
8670
+
8671
+ it ( 'checking `populated()` on a document array element (gh-8247)' , function ( ) {
8672
+ const authorSchema = Schema ( { name : String } ) ;
8673
+ const subSchema = Schema ( {
8674
+ author : { type : Schema . Types . ObjectId , ref : 'gh8247_Author' } ,
8675
+ comment : String
8676
+ } ) ;
8677
+ const pageSchema = Schema ( { title : String , comments : [ subSchema ] } ) ;
8678
+ const Author = db . model ( 'gh8247_Author' , authorSchema ) ;
8679
+ const Page = db . model ( 'gh8247_Page' , pageSchema ) ;
8680
+
8681
+ return co ( function * ( ) {
8682
+ const doc = yield Author . create ( { name : 'test author' } ) ;
8683
+ yield Page . create ( { comments : [ { author : doc . _id } ] } ) ;
8684
+
8685
+ const fromDb = yield Page . findOne ( ) . populate ( 'comments.author' ) ;
8686
+ assert . ok ( Array . isArray ( fromDb . populated ( 'comments.author' ) ) ) ;
8687
+ assert . equal ( fromDb . populated ( 'comments.author' ) . length , 1 ) ;
8688
+ assert . equal ( fromDb . comments [ 0 ] . author . name , 'test author' ) ;
8689
+
8690
+ assert . ok ( fromDb . comments [ 0 ] . populated ( 'author' ) ) ;
8691
+ } ) ;
8692
+ } ) ;
8670
8693
} ) ;
You can’t perform that action at this time.
0 commit comments