-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Path generic #13117
Add Path generic #13117
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -339,3 +339,34 @@ function gh12136() { | |||
} | ||||
|
||||
} | ||||
|
||||
async function gh13070() { | ||||
interface IParent { | ||||
name: string; | ||||
child: Types.ObjectId; | ||||
} | ||||
interface IChild { | ||||
name: string; | ||||
parent: Types.ObjectId; | ||||
} | ||||
|
||||
const parentSchema = new Schema( | ||||
{ | ||||
name: { type: String, required: true }, | ||||
child: { type: Schema.Types.ObjectId, ref: 'Child', required: true } | ||||
}); | ||||
|
||||
const childSchema = new Schema( | ||||
{ | ||||
name: { type: String, required: true }, | ||||
parent: { type: Schema.Types.ObjectId, ref: 'Parent', required: true } | ||||
}); | ||||
|
||||
const parent = model<IParent>('Parent', parentSchema); | ||||
const child = model<IChild>('Child', childSchema); | ||||
|
||||
const doc = await parent.findOne(); | ||||
await child.populate<{child: IChild}>(doc, 'child'); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't actually test that the result doc is correctly populated. Missed this: mongoose/test/types/populate.test.ts Line 126 in 7d2c511
|
||||
|
||||
|
||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,7 +303,8 @@ declare module 'mongoose' { | |
callback?: Callback<(HydratedDocument<T, TMethodsAndOverrides, TVirtuals>)[]>): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>; | ||
populate(doc: any, options: PopulateOptions | Array<PopulateOptions> | string, | ||
callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>; | ||
|
||
populate<Paths={}>(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string): Promise<MergeType<this, Paths>>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you had actually tested the populate doc result, you'd see that |
||
populate<Paths={}>(docs: any, options: PopulateOptions | Array<PopulateOptions> | string, callback?: Callback<MergeType<this, Paths>>): void; | ||
|
||
/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */ | ||
validate(callback?: CallbackWithoutResult): Promise<void>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always use capitalized names for models