File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,14 @@ Be wary of circular dependencies. Direct references must be declared after the r
127
127
128
128
<<< @/docs/tutorials/snippets/mongoose/virtual-references.ts
129
129
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
+
130
138
## Register hook
131
139
132
140
Mongoose allows the developer to add pre and post [ hooks / middlewares] ( http://mongoosejs.com/docs/middleware.html ) to the schema.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments