Skip to content
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

Support for refPath and dynamic population #11

Open
hennessyevan opened this issue May 31, 2019 · 3 comments
Open

Support for refPath and dynamic population #11

hennessyevan opened this issue May 31, 2019 · 3 comments

Comments

@hennessyevan
Copy link

Is there a way to implement a refPath for the Type.ref() pattern?

I'm talking about this https://mongoosejs.com/docs/populate.html#dynamic-ref

@ManAnRuck
Copy link

@hennessyevan do you found a solution for this?

@hennessyevan
Copy link
Author

I gave up on using these sorts of libs and just went for straight mongoose with types 🤷🏻‍♂️

@tezqa
Copy link

tezqa commented May 16, 2022

You can just declare your field with the regular mongoose syntax, inside your ts-mongoose schema:

For example:

const MyModelSchema = createSchema(
  {
    type: Type.string({
      required: true,
      index: true,
      enum: Object.values(ItemType)
    }),
    items: { type: Schema.Types.ObjectId, refPath: "type" },
  }
)

const MyModel = typedModel("MyModel", MyModelSchema)

// ...

await MyModel.find().populate("items)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants