【问题标题】:TypeORM - Add extra column when custom column on OneToManyTypeORM - 在 OneToMany 上自定义列时添加额外列
【发布时间】:2021-11-01 18:15:59
【问题描述】:

我想为我的@ManyToOne 实体创建一个自定义列。当我使用此代码时

结果是:

已添加countryId 列。我必须做些什么来解决这个问题?

【问题讨论】:

    标签: node.js nestjs typeorm


    【解决方案1】:

    为此,您必须像这样使用装饰器@RelationId

    export class Province {
      //...
      @Column()
      @RelationId((province: Province) => province.country)
      public countryId: number;
    }
    

    请使用下次代码定义的块代码。

    【讨论】:

    • 感谢您提及。但结果是一样的。列countryId 仍然出现。
    • 啊,所以从@JoinColumn 搭上name
    • 嗯,对了,你能给我一个解决方案吗?
    • 我刚刚在上面的评论中做到了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-28
    • 2013-03-01
    • 2021-06-12
    • 1970-01-01
    相关资源
    最近更新 更多