更新Project
实体时出现以下错误:EntityColumnNotFound: No entity column "context.physicalPresets" was found
。
qazxsw poi嵌入qazxsw poi,如ProjectContext
所述。 Project
与https://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关系,如果是,如何?
正如文档解释的那样,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);
}