Skip to main content

Function: ForeignKey()

ForeignKey(referencedEntity, options?): PropertyDecorator

Defined in: src/decorators/PrimaryKey.ts:57

Property decorator defining an explicit foreign key column referencing another entity.

Parameters​

ParameterTypeDescription
referencedEntity() => FunctionLambda returning the referenced parent entity class.
options?ForeignKeyOptionsColumn naming and referenced column settings.

Returns​

PropertyDecorator

Usecase​

Link relational child entities to their parent entity tables.

Example​

@ForeignKey(() => User)
userId!: number;