Как я могу установить ограничение на два столбца с TypeORM? - PullRequest
0 голосов
/ 26 апреля 2020

У меня есть «тип-сущность», у которой есть подтип - категория:

@Entity("types")
export class Type {

  @PrimaryGeneratedColumn({ zerofill: true })
  id: number;

  @Index({ unique: true })
  @Column("varchar")
  code: string;

  @Index()
  @Column("varchar", { nullable: true })
  name: string;

  @ManyToOne(t => TypeCategory, c => c.code)
  category: TypeCategory;

}

@Entity("types_categories")
export class TypeCategory {

  @PrimaryGeneratedColumn({ zerofill: true })
  id: number;

  @Index({ unique: true })
  @Column("varchar")
  code: string;

  @Index()
  @Column("varchar", { nullable: true })
  name: string;

}

И у меня есть правило-сущность, у которой указан тип c type:

@Entity("rules")
export class Rule {

  @PrimaryGeneratedColumn({ zerofill: true })
  id: number;

  @Column("varchar", { nullable: false })
  value: string;

  @ManyToOne(t => Type, type => type.code)
  type: Type;

}

На данный момент я могу установить любой type для «правила-сущности». Моя задача состоит в том, чтобы ограничить тип для "rule-entity" в двух столбцах: Type.id and Type.category.id. Как я могу это сделать?

...