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.
| Public Methods | ||
|---|---|---|
| public | Create a new instance of the associated model and associate it with this. | |
| public | Get the associated instance. | |
| public | Set the associated model. | |
| From class Association | ||
|---|---|---|
| public | The type of the association. | |
| public | ||
| public | ||
Create a new instance of the associated model and associate it with this.
Get the associated instance.
| Name | Type | Attribute | Description |
|---|---|---|---|
| instances | Model | Array<Model> |
source instances | |
| options | Object |
|
find options |
| 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 |
Set the associated model.
| Name | Type | Attribute | Description |
|---|---|---|---|
| sourceInstance | Model |
the source instance | |
| associatedInstance | <Model> | string | number |
|
An persisted instance or the primary key of an instance to associate with this. Pass |
| options | Object |
|
Options passed to getAssociation and |
| Promise |
Copyright © 2014–present Sequelize contributors
Licensed under the MIT License.
https://sequelize.org/master/class/lib/associations/has-one.js~HasOne.html