NestJS + TypeORM 中的多对多关系 - 结果 table 的自定义名称?

Many to many relationship in NestJS + TypeORM - custom names for resultant table?

我有一个用户和产品 table,多对多关系与:

@Entity('User')
  export class User {
  ...
    @ManyToMany(() => Product)
    @JoinTable({ name: 'UserProduct' })
    Products: Product[];
}

在生成的 UserProduct table 中产生预期结果,其中包含 2 列:userId、productId - 我如何自定义名称以符合我的惯例?即 UserId, ProductId

您看过 @JoinTable 的 TypeORM 文档了吗?似乎它们允许您使用 joinColumn.

使用特定的列命名要求覆盖标准命名约定

我想你想要这样的东西:

@JoinTable({
    name: "UserProduct",
    joinColumn: {
        name: "UserId",
        referencedColumnName: "id"
    },
    inverseJoinColumn: {
        name: "ProductId",
        referencedColumnName: "id"
    }
})