Skip to content

Commit 4bf5daa

Browse files
Gustavo MendonçaRomakita
authored andcommitted
docs: Added dynamic reference documentation
1 parent 5af9825 commit 4bf5daa

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

docs/tutorials/mongoose.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ Be wary of circular dependencies. Direct references must be declared after the r
127127

128128
<<< @/docs/tutorials/snippets/mongoose/virtual-references.ts
129129

130+
### Dynamic References
131+
132+
`@tsed/mongoose` supports `mongoose` dynamic references between defined models.
133+
134+
This works by having a field with the referenced object model's name and a field with the referenced field.
135+
136+
<<< @/docs/tutorials/snippets/mongoose/dynamic-references.ts
137+
130138
## Register hook
131139

132140
Mongoose allows the developer to add pre and post [hooks / middlewares](http://mongoosejs.com/docs/middleware.html) to the schema.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Model, Ref, DynamicRef} from "@tsed/mongoose";
2+
import {Enum, Required} from "@tsed/common"
3+
4+
@Model()
5+
export class DynamicRef {
6+
@DynamicRef('type')
7+
dynamicRef: Ref<ModelA | ModelB>
8+
9+
@Enum(['Mode lA', 'ModelB'])
10+
type: string // This field has to match the referenced model's name
11+
}

0 commit comments

Comments
 (0)