【问题标题】:TypeORM: Can I have an entity with OneToOne relation ship that has the type of the other entity and the primary key time of the other entity?TypeORM:我可以拥有一个具有 OneToOne 关系的实体,它具有另一个实体的类型和另一个实体的主键时间吗?
【发布时间】:2022-07-08 00:38:17
【问题描述】:

这就是我现在制作实体的方式:

User.entity.ts

@Entity()
export class User {
  @PrimaryGeneratedColumn('increment')
  id: number;
  ...

Client.entity.ts

@Entity()
export class Client {
  @OneToOne(() => Utente, {primary: true, cascade: true})
  @JoinColumn({name: 'id'})
  id: Utente;
  ...

我可以同时将具有numberUser 的客户端实体作为一个类型吗?如果是,我该怎么做?

非常感谢!

【问题讨论】:

    标签: typescript typeorm tsc


    【解决方案1】:

    好吧,我刚刚在这里找到了正确的答案:

    https://typeorm.io/relations-faq#how-to-use-relation-id-without-joining-relation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 2017-09-25
      • 2018-10-14
      相关资源
      最近更新 更多