TypeORM:保存时无法读取未定义的 属性 'inverseJoinColumns'

TypeORM: Cannot read property 'inverseJoinColumns' of undefined when saving

用例:如果用户尚未在数据库中创建,请创建它 - 如果用户已存在,请更新它。

这个逻辑有效。由于TypeORM的.save()更新实体或在不可用时更新它们,我想使用这种方法。

我的问题:创建有效但无法更新。执行此操作时,它会从 RelationIdLoader 中抛出此错误:

this.userRepository.save(user); // user = newly created or updated entity

TypeError: Cannot read property 'inverseJoinColumns' of undefined

更新的和创建的唯一区别是更新的有一个id属性,这是一个uuid/string。

更新

@PrimaryGeneratedColumn('uuid') public id: string;

... // some columns without relations

@OneToMany(type => Finding, finding => finding.reporter)
public reportedFindings: Finding[];

@OneToMany(type => Finding, finding => finding.responsible)
public responsibleFindings: Finding[];

@ManyToMany(type => DataCenter)
public dataCenterResponsiblities: DataCenter[];

@ManyToMany(type => Finding)
public informedFindings: Finding[];

正如@pleerock 指出的那样,所有 @ManyToMany 都必须在拥有方包含 @JoinTable 装饰器。

所以我的实际问题的具体解决方案如下:

@ManyToMany(type => DataCenter)
@JoinTable()
public dataCenterResponsiblities: DataCenter[];

@JoinTable()
@ManyToMany(type => Finding)
public informedFindings: Finding[];

This is actually well described in the docs.