一个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;
}
简而言之,我想创建两个外键。从User.profileId
到Profile.id
和从Profile.userId
到User.Id
。这是我的问题的最佳实践解决方案吗?