Mixin HasOne

View code

One-to-one association

In the API reference below, replace Association with the actual name of your association, 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.


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 a persisted instance to associate with this. Pass null or undefined to remove the association.
[options]ObjectOptions passed to getAssociation and target.save

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