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