typegoose when compared to other relational ORMs such as sequelize or
typeorm. You can read more about relations (references) in typegoose [here](https://mongoosejs.com/docs/populate
.html)
There are multiple ways to set of references in Typegoose. These are intended as a starting point.
One to Many/Many To One Example
To set up a one to many/many to one relationship in Typegoose, you will store a reference in your document. For example, lets add sub tasks to our todo items by storing atodoItem ref on our subTask and an array of sub-tasks on our todoItem entity.
- Todo Item
- Subtask
todo-item/todo-item.entity.ts
@Relation and @Connection to our DTOs
- Todo Item
- Subtask
todo-item/todo-item.dto.ts
Many To Many Example
In this example, we’ll addtags to todoItems by storing an array of tag references on the todoItems.
- Todo Item
- Tag
todo-item/todo-item.entity.ts
@Connection to our DTOS
- Todo Item
- Tag
todo-item/todo-item.dto.ts
Discriminators
Typegoose supports mongoose discriminators.nestjs-query provides support for them through the NestjsQueryTypegooseModule.
To use discriminators you need to define them in your NestjsQueryTypegooseModule.forFeature call.
When working with discriminators, nestjs-query requires you to provide a service class for each discriminated entity. This is necessary for the auto-generated resolvers to be created correctly. These service classes are also the perfect place to add any custom business logic for your discriminated entities.
todo-item/todo-item.module.ts