Mixin BelongsTo

View code

One-to-one association

In the API reference below, replace Assocation with the actual name of your association, e.g. for User.belongsTo(Project) the getter will be user.getProject().


getAssociation([options]) -> Promise.<Instance>

View code

Get the associated instance.

Params:

NameTypeDescription
[options]Object
[options.scope]String | BooleanApply a scope on the related model, or remove its default scope by passing false.
[options.schema]StringApply a schema on the related model

setAssociation([newAssociation], [options]) -> Promise

View code

Set the associated model.

Params:

NameTypeDescription
[newAssociation]Instance | String | NumberAn persisted instance or the primary key of an instance to associate with this. Pass null or undefined to remove the association.
[options]ObjectOptions passed to this.save
[options.save=true]BooleanSkip saving this after setting the foreign key if false.

createAssociation([values], [options]) -> Promise

View code

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

Params:

NameTypeDescription
[values]Object
[options]ObjectOptions 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