From c9e48750c94730fab7162e24c6930c1b217a2aab Mon Sep 17 00:00:00 2001 From: gimyboya Date: Sat, 12 Jun 2021 16:22:35 +0800 Subject: [PATCH] fix: used the relevant example --- .../docs/persistence/typegoose/relations.mdx | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/documentation/docs/persistence/typegoose/relations.mdx b/documentation/docs/persistence/typegoose/relations.mdx index 465c6d96f..b073867da 100644 --- a/documentation/docs/persistence/typegoose/relations.mdx +++ b/documentation/docs/persistence/typegoose/relations.mdx @@ -265,12 +265,24 @@ export class TodoItemEntity extends Base { -```ts title="tag/tag.entity.ts" {15-21} -import { Prop, modelOptions, Ref } from '@typegoose/typegoose'; +```ts title="tag/tag.entity.ts" {33-38} import { Base } from '@typegoose/typegoose/lib/defaultClasses'; +import { Prop, modelOptions, Ref } from '@typegoose/typegoose'; +import { Types } from 'mongoose'; +import { TodoItemEntity } from '../todo-item/todo-item.entity'; + +@modelOptions({ + schemaOptions: { + timestamps: true, + collection: 'tags', + toObject: { virtuals: true }, + }, +}) +export class TagEntity implements Base { + _id!: Types.ObjectId; + + id!: string; -@modelOptions({ schemaOptions: { timestamps: true } }) -export class TagEntity extends Base { @Prop({ required: true }) name!: string; @@ -280,18 +292,18 @@ export class TagEntity extends Base { @Prop() updatedAt!: Date; - @Prop({ - ref: () => TodoItemEntity, - localField: '_id', - foreignField: 'tags', - }) - todoItems: Ref[]; - @Prop() createdBy?: string; @Prop() updatedBy?: string; + + @Prop({ + ref: 'TodoItemEntity', + localField: '_id', + foreignField: 'tags', + }) + todoItems?: Ref[]; } ```