TypeORM - 一对多:EntityColumnNotFound:未找到实体列“context.physicalPresets”

问题描述 投票:0回答:1

更新Project实体时出现以下错误:EntityColumnNotFound: No entity column "context.physicalPresets" was found

qazxsw poi嵌入qazxsw poi,如ProjectContext所述。 Projecthttps://typeorm.io/#/embedded-entities实体有一个OneToMany关系。

ProjectContext
Physical
@Entity()
export class Project extends BaseEntityModel {
  // embedded
  @Column(type => ProjectContext)
  context: ProjectContext;
}

没有更多成功:

// embedded entity
@Entity()
export class ProjectContext {
  @OneToMany(type => Physical, physical => physical.project, {
    eager: true,
  })
  @JoinColumn()
  physicalPresets: Physical[];
}

我得到@Entity() export class Physical extends BaseEntityModel { @ManyToOne( type => Project, project => project.context.physicalPresets, {onDelete: 'CASCADE'}, ) project: Project; }

@Entity()
export class Physical extends BaseEntityModel {
 @ManyToOne(
    type => ProjectContext, projectContext => projectContext.physicalPresets,
    {onDelete: 'CASCADE'},
  )
  projectContext: ProjectContext;
}

是否可以在嵌入实体中建立OneToMany关系,如果是,如何?

typeorm
1个回答
1
投票

正如文档解释的那样,Entity metadata for Physical#projectContext was not found. Check if you specified a correct entity object and if it's connected in the connection options的更新方法:

部分更新实体。可以通过给定条件找到实体。与save方法不同,执行原始操作时不包括级联,关系和其他操作。

使用save方法解决 async update(entity: Project): Promise<UpdateResult> { return await this.repository.update(entity.id, entity); }

Repository

这是使用嵌入式实体执行OneToMany的正确方法。

No entity column [...] was found

另见: async update(entity: Project): Promise<Project> { return await this.repository.save(entity); }

© www.soinside.com 2019 - 2024. All rights reserved.