Mixin HasMany
View code One-to-many association
In the API reference below, replace Assocation(s)
with the actual name of your association, e.g. for User.belongsToMany(Project)
the getter will be user.getProjects()
.
getAssociations([options])
-> Promise.<Array.<Instance>>
View code Get everything currently associated with this, using an optional where clause
Params:
Name | Type | Description |
---|---|---|
[options] | Object | |
[options.where] | Object | An optional where clause to limit the associated models |
[options.scope] | String | Boolean | Apply a scope on the related model, or remove its default scope by passing false |
setAssociations([newAssociations], [options])
-> Promise
View code Set the associated models by passing an array of instances or their primary keys. Everything that it not in the passed array will be un-associated
Params:
Name | Type | Description |
---|---|---|
[newAssociations] | Array.<Instance | String | Number> | An array of instances or primary key of instances to associate with this. Pass null or undefined to remove all associations. |
[options] | Object | Options passed to target.findAll and update . |
[options.validate] | Object | Run validation for the join model |
addAssociations([newAssociations], [options])
-> Promise
View code Associate several instances with this
Params:
Name | Type | Description |
---|---|---|
[newAssociations] | Array.<Instance | String | Number> | An array of instances or primary key of instances to associate with this. Pass null or undefined to remove all associations. |
[options] | Object | Options passed to target.update . |
[options.validate] | Object | Run validation for the join model |
addAssociation([newAssociation], [options])
-> Promise
View code Associate several instances with this
Params:
Name | Type | Description |
---|---|---|
[newAssociation] | Instance | String | Number | An array of instances or primary key of instances to associate with this. Pass null or undefined to remove all associations. |
[options] | Object | Options passed to target.update . |
[options.validate] | Object | Run validation for the join model |
createAssociation([values], [options])
-> Promise
View code Create a new instance of the associated model and associate it with this.
Params:
Name | Type | Description |
---|---|---|
[values] | Object | |
[options] | Object | Options passed to target.create . |
removeAssociation([oldAssociated], [options])
-> Promise
View code Un-associate the instance
Params:
Name | Type | Description |
---|---|---|
[oldAssociated] | Instace | String | Number | Can be an Instance or its primary key |
[options] | Object | Options passed to target.update
|
removeAssociations([oldAssociated], [options])
-> Promise
View code Un-associate several instances
Params:
Name | Type | Description |
---|---|---|
[oldAssociated] | Array.<Instace | String | Number> | Can be an Instance or its primary key |
[options] | Object | Options passed to through.destroy
|
hasAssociation([instance], [options])
-> Promise
View code Check if an instance is associated with this.
Params:
Name | Type | Description |
---|---|---|
[instance] | Instace | String | Number | Can be an Instance or its primary key |
[options] | Object | Options passed to getAssociations |
hasAssociations([instances], [options])
-> Promise
View code Check if all instances are associated with this.
Params:
Name | Type | Description |
---|---|---|
[instances] | Array.<Instace | String | Number> | Can be an Instance or its primary key |
[options] | Object | Options passed to getAssociations |
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