The model on which hasOne has been called, on which the association methods will be added.
The model passed to hasOne. This model will receive the Foreign Key attribute.
The name of the attribute that the foreign key in the target model will reference.
The name of the Foreign Key attribute on the Target model.
The name of the Primary Key attribute of the Target model. Used by HasOneSetAssociationMixin.
Optional
parent: Association<Model<any, any>, Model<any, any>, string, NormalizedAssociationOptions<string>>Private
#privateReadonly
accessorsReadonly
inverseReadonly
optionsReadonly
parentA reference to the association that created this one.
The identifier of the relation on the source model.
The type of the association. One of HasMany
, BelongsTo
, HasOne
, BelongsToMany
The column name of the foreign key (on the target model)
negate isMultiAssociation instead
Creating an associations can automatically create other associations. This returns the initial association that caused the creation of the descendant associations.
The name of the attribute the foreign key points to. In HasOne, it is on the Source Model, instead of the Target Model (unlike targetKey). The foreignKey is on the Target Model.
use sourceKey
The Column Name of the source key.
Static
isCreate a new instance of the associated model and associate it with this.
See Model#create for a full explanation of options.
The created target model
the source instance
Optional
values: CreationAttributes<T>values to create associated model instance with
Optional
options: HasOneCreateAssociationMixinOptions<T>Options passed to target.create
and setAssociation.
Get the associated instance.
See HasOneGetAssociationMixinOptions for a full explanation of options. This method is mixed-in the source model prototype. See HasOneGetAssociationMixin.
source instances
Optional
options: HasOneGetAssociationMixinOptions<T>find options
Optional
options: HasOneGetAssociationMixinOptions<T>Set the associated model.
The associated instance, or null if disassociated.
the source instance
An persisted instance or the primary key of an instance to associate with this. Pass null
to remove the association.
Optional
options: HasOneSetAssociationMixinOptions<T>Options passed to getAssociation and target.save
Optional
options: HasOneSetAssociationMixinOptions<T>Static
associateOptional
options: HasOneOptions<SourceKey, TargetKey>Optional
parent: Association<any, Model<any, any>, string, NormalizedAssociationOptions<string>>Generated using TypeDoc
One-to-one association. See hasOne
This is almost the same as BelongsTo, but the foreign key will be defined on the target model.
In the API reference below, add the name of the association to the method, e.g. for
User.hasOne(Project)
the getter will beuser.getProject()
.