以http://typeorm.io/#/one-to-one-relations定义的两个实体为例
在 User 中定义了一对一关系,因此在 User 表中生成了外键列“profileId”。到现在为止还挺好。
但是我的“用户”实体已经有一个“idProfile”列,我希望这是建立关系的外键。如何告诉 TypeORM 使用此列而不是生成新列?
Nik*_*igi 10
您可以将列名传递给@JoinColumn():
@Entity()
class User {
@OneToOne(type => Profile)
@JoinColumn({ name: 'idProfile' })
profile: Profile
}
@Entity()
class Profile {
@PrimaryGeneratedColumn()
id: number
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8006 次 |
| 最近记录: |