BelongsTo
Extends:
One-to-one association
In the API reference below, add the name of the association to the method, e.g. for User.belongsTo(Project) the getter will be user.getProject().
See:
Method Summary
| Public Methods | ||
| public | Create a new instance of the associated model and associate it with this. | |
| public | Get the associated instance. | |
| public | async set(sourceInstance: Model, associatedInstance: Model | string | number, options: object): Promise Set the associated model. | |
Inherited Summary
| From class Association | ||
| public | The type of the association. | |
| public |  | |
| public |  | |
Public Methods
public async create(sourceInstance: Model, values: object, options: object): Promise<Model> source
Create a new instance of the associated model and associate it with this.
See:
- Model#create for a full explanation of options
public async get(instances: Model | Array<Model>, options: object): Promise<Model> source
Get the associated instance.
Params:
| 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 | 
See:
- Model.findOne for a full explanation of options
public async set(sourceInstance: Model, associatedInstance: Model | string | number, options: object): Promise source
Set the associated model.
Params:
| 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  | 
| options.save | boolean | 
 | Skip saving this after setting the foreign key if false. | 
 开发指南
  Reference
  Source
  开发指南
  Reference
  Source
  
   
    
  