Skip to content

postgrelize / ForeignKey

Variable: ForeignKey ​

ForeignKey: (target) => ModelPropertyDecorator

Defined in: src/decorators/foreign-key-decorator.ts:7

Marks the attribute as a foreign key to a model (also the v6 type ForeignKey<T> of the same name). Association decorators use it to find the foreign key; it does not change the column definition.

Parameters ​

target ​

ModelGetter

Function returning the referenced model.

Returns ​

ModelPropertyDecorator

An attribute decorator.

Example ​

ts
class Post extends Model {
  @ForeignKey(() => User)
  @Column(DataTypes.INTEGER)
  userId!: number;
}

Released under the MIT License.