【问题标题】:typeorm: Impossible to retrieve a joined valuetypeorm:无法检索连接值
【发布时间】:2020-04-30 12:10:33
【问题描述】:

我有一个对象的以下配置:

export class Network {
  @PrimaryColumn({ name: "id" })
  id: string;

  @Column("text")
  url: string;

  @ManyToOne(
    type => User,
    user => user.users,
    { nullable: true, onDelete: "SET NULL", onUpdate: "CASCADE" }
  )  
  csm: User;

  get_data(): {} {
        return {
          id: this.id,
          url: this.url,
          csm: this.csm ? this.csm.id : null,
        };
      }
}

User 是另一个类,它不涉及网络 当我保存数据时,它工作正常: 在我的表中,我有一列 csmId 用适当的用户 ID 来完成。 实现这些价值的程序看起来像 my_network.csm=csm 其中 csm 是一个用户对象。 现在,当我尝试使用函数get_data() 检索我的数据时,csm 始终为空,无论如何。其他值得到适当满足 有人可以帮忙吗? 非常感谢

【问题讨论】:

  • thisget_data() 函数中是什么?
  • @noamsteiner:this是网络对象。我改变了我的描述,让你更好地理解。

标签: typescript typeorm many-to-one


【解决方案1】:

答案是:添加 eager(或lazy),这样连接就自动完成了

【讨论】:

    猜你喜欢
    • 2021-04-18
    • 2019-08-13
    • 2021-09-04
    • 2019-08-02
    • 2021-12-03
    • 2020-11-25
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    相关资源
    最近更新 更多