import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, OneToMany, } from 'typeorm'; import { ApiProperty } from '@nestjs/swagger'; @Entity() export class Topic { @ApiProperty({ description: '主键id', type: 'int' }) @PrimaryGeneratedColumn() id: number; @ApiProperty({ description: '名字', type: 'string' }) @Column() name: string; @ApiProperty({ description: '描述', type: 'string' }) @Column({ nullable: true }) description: string; @ApiProperty({ description: '父级Topic', type: 'Topic' }) @ManyToOne((type) => Topic, (topic) => topic.children, { nullable: true }) parent: Topic; @ApiProperty({ description: '子级Topic', type: 'Topic[]' }) @OneToMany((type) => Topic, (topic) => topic.parent) children: Topic[]; }