HasOne
Extends:
One-to-one association
In the API reference below, add the name of the association to the method, 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.
See:
Method Summary
| Public Methods | ||
| public |
create(values: Object, options: Object): Promise Create a new instance of the associated model and associate it with this. |
|
| public |
Get the associated instance. |
|
| public |
Set the associated model. |
|
Inherited Summary
| From class Association | ||
| public |
associationType: string The type of the association. |
|
| public |
|
|
| public |
|
|
Public Methods
public create(values: Object, options: Object): Promise source
Create a new instance of the associated model and associate it with this.
Params:
| Name | Type | Attribute | Description |
| values | Object |
|
|
| options | Object |
|
Options passed to |
Return:
| Promise |
See:
- Model#create for a full explanation of options
public get(options: Object): Promise<Model> source
Get the associated instance.
Params:
| Name | Type | Attribute | 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 |
See:
- Model.findOne for a full explanation of options
public set(newAssociation: Model | String | Number, options: Object): Promise source
Set the associated model.
Params:
| Name | Type | Attribute | Description |
| newAssociation | Model | String | Number |
|
An persisted instance or the primary key of a persisted instance to associate with this. Pass |
| options | Object |
|
Options passed to getAssociation and |
Return:
| Promise |
Home
Reference
Source
Repository