【问题标题】:TypeORM OneToMany relationship in the same entity同一实体中的 TypeORM OneToMany 关系
【发布时间】:2019-11-20 16:28:42
【问题描述】:

我正在努力与同一实体创建 OneToMany 关系。在 TypeORM 中可以吗?

假设我有一个实体:

export class X {
  @PrimaryGeneratedColumn()
  id: number;

  @OneToMany( what here???? ) 
  tests: X[];
}

有人可以帮助我吗?提前致谢。

【问题讨论】:

    标签: orm entity typeorm


    【解决方案1】:

    试试这个方法:

    export class X {
      @PrimaryGeneratedColumn()
      id: number;
    
      @OneToMany(type => X, x => x.belongsToTest ) 
      tests: X[];
    
      @ManyToOne(type => X, x => x.tests)
      belongsToTest: X;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 2019-12-25
      相关资源
      最近更新 更多