【问题标题】:Attribute contains only ID, not whole entity, in persisted TypeORM entity在持久化的 TypeORM 实体中,属性仅包含 ID,而不是整个实体
【发布时间】:2020-11-12 14:51:40
【问题描述】:

我有这个实体类:

@Entity("organization")
export class OrganizationEntity {

    // ...

    @PrimaryColumn({name: "party_id"})
    @OneToOne(() => PartyEntity, {cascade: true})
    @JoinColumn({name: "party_id", referencedColumnName: "id"})
    party: PartyEntity

}

然后我创建一个新的OrganizationEntity 并将其持久化:

const savedOrganizationEntity = await this.organizationTypeOrmRepository.save(organizationEntity);
// see Repository.save

但是,返回的savedOrganizationEntity 在字段party 中包含一个字符串,而不是PartyEntity 对象。

如何解决此问题,使OrganizationEntity.party 包含PartyEntity,而不是字符串?

【问题讨论】:

    标签: node.js typescript orm nestjs typeorm


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 1970-01-01
      • 2018-02-16
      • 2011-08-09
      • 1970-01-01
      • 2011-07-16
      • 2013-11-06
      相关资源
      最近更新 更多