ManyToMany 关系的 TypeORM 重复键值

L. *_*ste 5 many-to-many typescript typeorm nestjs

上下文
我使用 TypeORM 和 NestJS。
我有两个实体:

  • 锻炼
  • 锻炼

一次锻炼可以进行多次锻炼,一次锻炼可以进行多次锻炼。为了实现这一点,我使用了 ManyToMany 关系。

锻炼实体

@Entity()
export class Workout {
  @PrimaryGeneratedColumn()
  id: number;

  @JoinTable()
  @ManyToMany(() => Exercise, (exercise) => exercise.workouts)
  exercises: Exercise[];

}
Run Code Online (Sandbox Code Playgroud)

运动实体

@Entity()
export class Exercise {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToMany(() => Workout, (workout) => workout.exercises)
  workouts: Workout[];
}
Run Code Online (Sandbox Code Playgroud)

一切正常,但当我duplicate key value violates unique constraint尝试使用两个相同的练习创建锻炼时,我收到一条错误消息。

问题:如何在 ManyToMany 关系中拥有重复的实体?