postgrelize / HasOne
Variable: HasOne ​
HasOne: (
target,options?) =>ModelPropertyDecorator
Defined in: src/decorators/association-decorators.ts:17
Adds a hasOne association; the foreign key is on the target. The property name is the alias (as). The foreign key is the attribute of the target marked with @ForeignKey for this model, unless options.foreignKey is given.
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 ​
class User extends Model {
@HasOne(() => Profile)
profile!: Profile;
}