I'm facing an issue while trying to create a foreign key relationship in TypeORM where the foreign key references a composite primary key. I expect the foreign key to also act as a primary key in the table where it is defined, but instead, I receive a "DataTypeNotSupportedError" when attempting to implement this.
Steps to reproduce
@Entity()
export class FirstEntity {
@PrimaryColumn()
primaryKey1: string;
@PrimaryColumn()
primaryKey2: string;
}
@Entity()
export class SecondEntity {
@PrimaryColumn()
column1: string;
@PrimaryColumn()
@ManyToOne(() => FirstEntity)
@JoinColumn([
{ name: 'primaryKey1', referencedColumnName: 'primaryKey1' },
{ name: 'primaryKey2', referencedColumnName: 'primaryKey2' },
])
firstEntity: FirstEntity;
}
Environment:
Node.js version: v18.13.0
TypeScript version: 4.7.4
TypeORM version: 0.3.16
Operating System: Windows 11
Expected Behavior: I expect to be able to define a foreign key in TypeORM that references a composite primary key and also acts as a primary key in the table where it is defined.
Actual Behavior: Instead of being able to define the foreign key as a primary key, I encounter a "DataTypeNotSupportedError" when trying to implement this relationship.
Please note that I have already checked the dependencies, devDependencies, and versions mentioned above, and they appear to be correctly installed in my environment.
I tried creating a foreign key to a table with a primary key. I wanted my foreign key also to be part of a primary. TypeORM throws DataTypeNotSupportedError.