diff --git a/docs/tutorials/mongoose.md b/docs/tutorials/mongoose.md index f73345fa408..c667de61002 100644 --- a/docs/tutorials/mongoose.md +++ b/docs/tutorials/mongoose.md @@ -127,6 +127,14 @@ Be wary of circular dependencies. Direct references must be declared after the r <<< @/docs/tutorials/snippets/mongoose/virtual-references.ts +### Dynamic References + +`@tsed/mongoose` supports `mongoose` dynamic references between defined models. + +This works by having a field with the referenced object model's name and a field with the referenced field. + +<<< @/docs/tutorials/snippets/mongoose/dynamic-references.ts + ## Register hook Mongoose allows the developer to add pre and post [hooks / middlewares](http://mongoosejs.com/docs/middleware.html) to the schema. diff --git a/docs/tutorials/snippets/mongoose/dynamic-references.ts b/docs/tutorials/snippets/mongoose/dynamic-references.ts new file mode 100644 index 00000000000..d9274ef4d8c --- /dev/null +++ b/docs/tutorials/snippets/mongoose/dynamic-references.ts @@ -0,0 +1,11 @@ +import {Model, Ref, DynamicRef} from "@tsed/mongoose"; +import {Enum, Required} from "@tsed/common" + +@Model() +export class DynamicRef { + @DynamicRef('type') + dynamicRef: Ref + + @Enum(['Mode lA', 'ModelB']) + type: string // This field has to match the referenced model's name +} \ No newline at end of file