Documentation / zerotal / orm / hasMany
Function: hasMany()
hasMany(
related,options): (_value,context) =>void
Defined in: packages/orm/src/model/decorators/hasMany.ts:27
Declare a one-to-many relation: the parent owns many related rows, matched by a
foreign key on the related table (e.g. a User has many Posts).
Parameters
related
() => unknown
Lazy factory returning the related model class.
options
HasManyOptions
Foreign/local key configuration.
Returns
(_value, context) => void
Example
class User extends BaseModel {
\@hasMany(() => Post, { foreignKey: 'user_id' })
posts!: HasMany<Post>;
}