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?
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With