belongsTo
A belongsTo
relationship is a many-to-one
relationship. For instance, a Post
may belong to a User
.
The first value passed to belongsTo
is a WireBox mapping to the related entity.
Quick determines the foreign key of the relationship based on the entity name and key values. In this case, the Post
entity is assumed to have a userId
foreign key. You can override this by passing a foreign key in as the second argument:
The inverse of belongsTo
is hasMany
or hasOne
.
Updating
To update a belongsTo
relationship, use the associate
method. associate
takes the entity to associate as the only argument.
Note:
associate
does not automatically save the entity. Make sure to callsave
when you are ready to persist your changes to the database.
Removing
To remove a belongsTo
relationship, use the dissociate
method.
Note:
dissociate
does not automatically save the entity. Make sure to callsave
when you are ready to persist your changes to the database.
Last updated