2

一个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.profileIdProfile.id和从Profile.userIdUser.Id。这是我的问题的最佳实践解决方案吗?

4

0 回答 0