@@ -108,8 +108,10 @@ describe('model', function() {
108108 users : [ { ref : 'User' , type : Schema . Types . ObjectId } ]
109109 } ) ;
110110
111- db . model ( 'UserTestHydrate' , userSchema ) ;
112- const Company = db . model ( 'CompanyTestHyrdrate' , companySchema ) ;
111+ db . deleteModel ( / U s e r / ) ;
112+ db . deleteModel ( / C o m p a n y / ) ;
113+ db . model ( 'User' , userSchema ) ;
114+ const Company = db . model ( 'Company' , companySchema ) ;
113115
114116 const users = [ { _id : new mongoose . Types . ObjectId ( ) , name : 'Val' } ] ;
115117 const company = { _id : new mongoose . Types . ObjectId ( ) , name : 'Booster' , users : [ users [ 0 ] ] } ;
@@ -144,6 +146,7 @@ describe('model', function() {
144146 count : true
145147 } ) ;
146148
149+ db . deleteModel ( / U s e r / ) ;
147150 const User = db . model ( 'User' , UserSchema ) ;
148151 const Story = db . model ( 'Story' , StorySchema ) ;
149152
@@ -173,5 +176,26 @@ describe('model', function() {
173176
174177 assert . strictEqual ( hydrated . storiesCount , 2 ) ;
175178 } ) ;
179+
180+ it ( 'sets hydrated docs as populated (gh-15048)' , async function ( ) {
181+ const userSchema = new Schema ( {
182+ name : String
183+ } ) ;
184+ const companySchema = new Schema ( {
185+ name : String ,
186+ users : [ { ref : 'User' , type : Schema . Types . ObjectId } ]
187+ } ) ;
188+
189+ db . deleteModel ( / U s e r / ) ;
190+ const User = db . model ( 'User' , userSchema ) ;
191+ const Company = db . model ( 'Company' , companySchema ) ;
192+
193+ const users = [ { _id : new mongoose . Types . ObjectId ( ) , name : 'Val' } ] ;
194+ const company = { _id : new mongoose . Types . ObjectId ( ) , name : 'Acme' , users : [ users [ 0 ] ] } ;
195+
196+ const c = Company . hydrate ( company , null , { hydratedPopulatedDocs : true } ) ;
197+ assert . ok ( c . populated ( 'users' ) ) ;
198+ assert . ok ( c . users [ 0 ] instanceof User ) ;
199+ } ) ;
176200 } ) ;
177201} ) ;
0 commit comments