# Decorator DynamicRef
Decorator mongoose propertyModule | import { DynamicRef } from "@tsed/mongoose" |
---|---|
Source | /packages/mongoose/src/decorators/dynamicRef.ts |
# Overview
function DynamicRef(refPath: string): PropertyDecorator;
export type DynamicRef<T> = T | string;
# Description
Define a property as mongoose reference to other Model (decorated with @Model).
# Example
@Model()
class FooModel {
@DynamicRef('type')
field: DynamicRef<OtherFooModel | OtherModel>
@Enum(['OtherFooModel', 'OtherModel'])
type: string
}
@Model()
class OtherFooModel {
}
@Model()
class OtherModel {
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Other topics
- Session & cookies
- Passport.js
- Keycloak
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- AWS
- Seq
- OIDC
- Stripe
- Controllers
- Providers
- Model
- JsonMapper
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Exceptions
- Throw HTTP Exceptions
- Cache
- Hooks
- Response Filter
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing
- Customize 404