Back to Sequelize

BelongsTo

static/v4/class/lib/associations/belongs-to.js~BelongsTo.html

latest3.6 KB
Original Source

publicclass| source

BelongsTo

Extends:

Association → BelongsTo

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(values: Object, options: Object): Promise

Create a new instance of the associated model and associate it with this.

| | | public |

get(options: Object): Promise<Model>

Get the associated instance.

| | | public |

set(newAssociation: Model | String | Number, options: Object): Promise

Set the associated model.

| |

Inherited Summary

| From class Association | | public |

associationType: string

The type of the association.

| | | public |

source: Model

| | | public |

target: Model

| |

Public Methods

publiccreate(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 |

  • optional

| | | options | Object |

  • optional

|

Options passed to target.create and setAssociation.

|

Return:

| Promise |

See:

  • Model#create for a full explanation of options

publicget(options: Object): Promise<Model> source

Get the associated instance.

Params:

| Name | Type | Attribute | Description | | options | Object |

  • optional

| | | options.scope | String | Boolean |

  • optional

|

Apply a scope on the related model, or remove its default scope by passing false.

| | options.schema | String |

  • optional

|

Apply a schema on the related model

|

Return:

| Promise<Model> |

See:

publicset(newAssociation: Model | String | Number, options: Object): Promise source

Set the associated model.

Params:

| Name | Type | Attribute | Description | | newAssociation | Model | String | Number |

  • optional

|

An persisted instance or the primary key of an instance to associate with this. Pass null or undefined to remove the association.

| | options | Object |

  • optional

|

Options passed to this.save

| | options.save | Boolean |

  • optional
  • default: true

|

Skip saving this after setting the foreign key if false.

|

Return:

| Promise |