The model on which Model.belongsTo has been called, on which the association methods, as well as the foreign key attribute, will be added.
The model passed to Model.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>>Readonly
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 HasOneAssociation.sourceKey). The Association.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
The attribute name of the identifier
use foreignKey instead
negate isMultiAssociation instead
Creating an associations can automatically create other associations. This returns the initial association that caused the creation of the descendant associations.
Static
isPrivate
#mixinCreate a new instance of the associated model and associate it with this.
the source instance
values to create associated model instance with
Options passed to target.create
and setAssociation.
The created target model
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
Optional
options: BelongsToGetAssociationMixinOptions<T>find options
Optional
options: BelongsToGetAssociationMixinOptions<T>Protected
inferStatic
associateOptional
parent: Association<any, Model<any, any>, string, NormalizedAssociationOptions<string>>
One-to-one association See Model.belongsTo
This is almost the same as HasOneAssociation, 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()
.