Mixin HasOne
One-to-one association
In the API reference below, replace Association
with the actual name of your association, e.g. for User.hasOne(Project)
the getter will be user.getProject()
.
This is almost the same as belongsTo
with one exception. The foreign key will be defined on the target model.
getAssociation([options])
-> Promise.<Instance>
Get the associated instance.
Params:
Name | Type | Description |
---|---|---|
[options] | Object | |
[options.scope] | String | Boolean | Apply a scope on the related model, or remove its default scope by passing false |
[options.schema] | String | Apply a schema on the related model |
setAssociation([newAssociation], [options])
-> Promise
Set the associated model.
Params:
Name | Type | Description |
---|---|---|
[newAssociation] | Instance | String | Number | An instance or the primary key of an instance to associate with this. Pass null or undefined to remove the association. |
[options] | Object | Options passed to getAssociation and target.save |
createAssociation([values], [options])
-> Promise
Create a new instance of the associated model and associate it with this.
Params:
Name | Type | Description |
---|---|---|
[values] | Object | |
[options] | Object | Options passed to target.create and setAssociation. |
This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on IRC, open an issue or a create a pull request if you feel something can be improved. For help on how to write source code documentation see JSDoc and dox