Skip to content

Commit

Permalink
fix: used the relevant example
Browse files Browse the repository at this point in the history
  • Loading branch information
khawarizmus authored and doug-martin committed Jul 10, 2021
1 parent 50b09a0 commit c9e4875
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions documentation/docs/persistence/typegoose/relations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,24 @@ export class TodoItemEntity extends Base {
<TabItem value="tag">


```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;

Expand All @@ -280,18 +292,18 @@ export class TagEntity extends Base {
@Prop()
updatedAt!: Date;

@Prop({
ref: () => TodoItemEntity,
localField: '_id',
foreignField: 'tags',
})
todoItems: Ref<TodoItemEntity>[];

@Prop()
createdBy?: string;

@Prop()
updatedBy?: string;

@Prop({
ref: 'TodoItemEntity',
localField: '_id',
foreignField: 'tags',
})
todoItems?: Ref<TodoItemEntity>[];
}
```

Expand Down

0 comments on commit c9e4875

Please sign in to comment.