2017-12-20 41 views
0

ユースケース:ユーザーがまだデータベースに作成されていない場合は、作成します - ユーザーが既に存在する場合は更新します。TypeORM:保存時に 'inverseJoinColumns'プロパティが未定義です。

このロジックは機能します。 TypeORMの.save()は、エンティティを更新したり、利用できないときに更新したりするため、このメソッドを使用します。

私の問題:作業は作成しますが、更新はしません。

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

TypeError: Cannot read property 'inverseJoinColumns' of undefined

更新され、作成したものは、更新1は、UUID /文字列ですid性質を持っていることであるとの唯一の違いを:これを行うときにはRelationIdLoaderからこのエラーがスローされます。

更新

@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[]; 
+0

、あなたのエンティティを示しおそらくセットアップエンティティ関係が誤って – pleerock

+0

@pleerockはちょうどそのようにした必要があります。それを見ていただきありがとうございます。 – sandrooco

+1

'@ ManyToMany'を使用する場合は、' @ JoinTable'デコレータも置く必要があります(所有側でのみ、ここにのみ一方向の関係があるため)。 – pleerock

答えて

0

@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.

関連する問題