I'm using TypeORM with NestJS to establish a one-to-one relationship between two tables, but when I view the ERD in pgAdmin, it's showing up as a many-to-one/one-to-many relationship instead. I have included my code snippets and an image of the ERD for reference.
@Entity({ name: 'users' })
@ObjectType()
export class User {
@PrimaryGeneratedColumn()
@Field((type) => Int)
id: number
@Column()
@Field()
username: string
@Column({ nullable: true })
@Field({ nullable: true })
displayName?: string
@OneToOne(() => UserSetting)
@JoinColumn()
@Field({ nullable: true })
settings?: UserSetting
}
@Entity({ name: 'user_settings' })
@ObjectType()
export class UserSetting {
@PrimaryColumn()
@Field((type) => Int)
userId: number
@Column({ default: false })
@Field({ defaultValue: false })
receiveNotifications: boolean
@Column({ default: false })
@Field({ defaultValue: false })
receiveEmails: boolean
}
In pgAdmin, you can check relationship, this should appear as one-to-one. Has anyone else encountered this? Could there be something I'm missing in the configuration?
The issue we encountered appear due to the pgAdmin bug as per the below references.
The relationship we defined in code first approach is correct it is showing wrong relationship due to pgAdmin bugs. I have used DbBeaver to generate ER diagram and it shows correct relationship over there.