static/v3/api/associations/has-many/index.html
One-to-many association
In the API reference below, replace Association(s) with the actual name of your association, e.g. for User.hasMany(Project) the getter will be user.getProjects().
getAssociations([options]) -> Promise.<Array.<Instance>>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 |
| [options.schema] | String | Apply a schema on the related model |
setAssociations([newAssociations], [options]) -> PromiseSet the associated models by passing an array of instances or their primary keys. Everything that is not in the passed array will be un-associated
Params:
| Name | Type | Description |
|---|---|---|
| [newAssociations] | Array.<Instance | String |
| [options] | Object | Options passed to target.findAll and update. |
| [options.validate] | Object | Run validation for the join model |
addAssociations([newAssociations], [options]) -> PromiseAssociate several instances with this.
Params:
| Name | Type | Description |
|---|---|---|
| [newAssociations] | Array.<Instance | String |
| [options] | Object | Options passed to target.update. |
| [options.validate] | Object | Run validation for the join model. |
addAssociation([newAssociation], [options]) -> PromiseAssociate one instance with this.
Params:
| Name | Type | Description |
|---|---|---|
| [newAssociation] | Instance | String |
| [options] | Object | Options passed to target.update. |
| [options.validate] | Object | Run validation for the join model. |
createAssociation([values], [options]) -> PromiseCreate 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]) -> PromiseUn-associate the instance.
Params:
| Name | Type | Description |
|---|---|---|
| [oldAssociated] | Instance | String |
| [options] | Object | Options passed to target.update |
removeAssociations([oldAssociatedArray], [options]) -> PromiseUn-associate several instances.
Params:
| Name | Type | Description |
|---|---|---|
| [oldAssociatedArray] | Array.<Instance | String |
| [options] | Object | Options passed to through.destroy |
hasAssociation([instance], [options]) -> PromiseCheck if an instance is associated with this.
Params:
| Name | Type | Description |
|---|---|---|
| [instance] | Instance | String |
| [options] | Object | Options passed to getAssociations |
hasAssociations([instances], [options]) -> PromiseCheck if all instances are associated with this.
Params:
| Name | Type | Description |
|---|---|---|
| [instances] | Array.<Instance | String |
| [options] | Object | Options passed to getAssociations |
countAssociations([options]) -> Promise.<Int>Count 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 |
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