DynamicRef
@tsed/mongoose
Usage
typescript
import { DynamicRef } from "@tsed/mongoose";
See /packages/orm/mongoose/src/types/decorators/dynamicRef.ts.
Overview
ts
function DynamicRef(refPath: string, ...types: Type<any>[]): PropertyDecorator;
export type DynamicRef<T> = T | string;
refPath (
string
): the path to apply the correct modeltypes (
Type<any>[]
): the classes to generate the correct json schema
Description
Define a property as mongoose reference to other Model (decorated with @Model).
Example
typescript
@Model()
class FooModel {
@DynamicRef('type')
field: DynamicRef<OtherFooModel | OtherModel>
@Enum(['OtherFooModel', 'OtherModel'])
type: string
}
@Model()
class OtherFooModel {
}
@Model()
class OtherModel {
}