Reputation: 452
Take the two entities defined at http://typeorm.io/#/one-to-one-relations
A one-to-one relation is defined in User and as a result a foreign key column "profileId" is generated in the User table. So far, so good.
But my "User" entity already has an "idProfile" column and I would like this to be the foreign key on which the relation is built. How can I tell TypeORM to use this column instead of generating a new one?
Upvotes: 8
Views: 13274
Reputation: 2309
You can pass the column name to @JoinColumn()
:
@Entity()
class User {
@OneToOne(type => Profile)
@JoinColumn({ name: 'idProfile' })
profile: Profile
}
@Entity()
class Profile {
@PrimaryGeneratedColumn()
id: number
}
Upvotes: 14