postgrelize / HasMany
Variable: HasMany ​
HasMany: (
target,options?) =>ModelPropertyDecorator
Defined in: src/decorators/association-decorators.ts:22
Adds a hasMany association; the foreign key is on the target. The property name is the alias (as).
Parameters ​
target ​
Function returning the associated model.
options? ​
Readonly<{ as?: string | Readonly<{ plural: string; singular: string; }>; constraints?: boolean; foreignKey?: string | Readonly<{ allowNull?: boolean; field?: string; name?: string; }>; hooks?: boolean; onDelete?: string; onUpdate?: string; scope?: Readonly<Record<string, unknown>>; sourceKey?: string; targetKey?: string; }>
Association options (foreignKey, onDelete, …).
Returns ​
An attribute decorator.
Example ​
ts
class User extends Model {
@HasMany(() => Post)
posts!: Post[];
}