要定义实体中的关系,请使用相应的装饰器。例如,要定义每个 User 可以有多张照片,请使用 @OneToMany() 装饰器

示例

import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm';
import { Photo } from '../photos/photo.entity';
@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;
  @Column()
  firstName: string;
  @Column()
  lastName: string;
  @Column({ default: true })
  isActive: boolean;
  @OneToMany(type => Photo, photo => photo.user)
  photos: Photo[];
}