1 つUser
は複数持つことができますProfiles
。にUser
のみを保存したいprofileId
。のProfile
IDを保存したいUser
。
ユーザー
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: string;
@Column({ nullable: true })
public profileId?: string;
@OneToOne(
type => Profile,
profile => profile.user
)
@JoinColumn()
profile: Profile;
}
プロフィール
@Entity()
export class Profile {
@PrimaryGeneratedColumn()
id: string;
@PrimaryColumn()
userId: string;
@OneToOne(
type => User,
user => user.profile
)
user: User;
}
簡単に言えば、2 つの外部キーを作成したいと考えています。からUser.profileId
へ、Profile.id
からProfile.userId
へUser.Id
。これは私の問題に対するベスト プラクティス ソリューションですか?