The model on which belongsTo has been called, on which the association methods, as well as the foreign key attribute, will be added.
The model passed to belongsTo.
The name of the Foreign Key attribute on the Source model.
The name of the attribute that the foreign key in the source model will reference, typically the Primary Key.
Optional
parent: Association<Model<any, any>, Model<any, any>, string, NormalizedAssociationOptions<string>>Private
#privateReadonly
accessorsThe column name of the foreign key
Readonly
optionsReadonly
parentA reference to the association that created this one.
The name of the attribute the foreign key points to. In belongsTo, this key is on the Target Model, instead of the Source Model (unlike sourceKey). The foreignKey is on the Source Model.
Readonly
targetThe column name of the target key
Readonly
targetThe identifier of the relation on the source model.
The type of the association. One of HasMany
, BelongsTo
, HasOne
, BelongsToMany
negate isMultiAssociation instead
Creating an associations can automatically create other associations. This returns the initial association that caused the creation of the descendant associations.
use targetKey
Static
isCreate a new instance of the associated model and associate it with this.
The created target model
the source instance
Optional
values: CreationAttributes<T>values to create associated model instance with
Optional
options: BelongsToCreateAssociationMixinOptions<T>Options passed to target.create
and setAssociation.
Get the associated instance.
See BelongsToGetAssociationMixinOptions for a full explanation of options. This method is mixed-in the source model prototype. See BelongsToGetAssociationMixin.
source instances
find options
Protected
inferSet the associated model.
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: BelongsToSetAssociationMixinOptions<T>options passed to this.save
Static
associateOptional
options: BelongsToOptions<SourceKey, TargetKey>Optional
parent: Association<any, Model<any, any>, string, NormalizedAssociationOptions<string>>Generated using TypeDoc
One-to-one association See belongsTo
This is almost the same as HasOne, but the foreign key will be defined on the source model.
In the API reference below, add the name of the association to the method, e.g. for
User.belongsTo(Project)
the getter will beuser.getProject()
.