Skip to content

Commit

Permalink
docs: Added dynamic reference documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Mendonça authored and Romakita committed Jul 20, 2019
1 parent 5af9825 commit 4bf5daa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/tutorials/mongoose.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions docs/tutorials/snippets/mongoose/dynamic-references.ts
Original file line number Diff line number Diff line change
@@ -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<ModelA | ModelB>

@Enum(['Mode lA', 'ModelB'])
type: string // This field has to match the referenced model's name
}

0 comments on commit 4bf5daa

Please sign in to comment.