不要怂,就是干,撸起袖子干!

Commit 803f3532 by Jan Aagaard Meier

[ci skip] Remove @see promise, and regenerate api docs. Closes #4560

1 parent 95f8fc27
<a name="belongstomany"></a> <a name="belongstomany"></a>
# Mixin BelongsToMany # Mixin BelongsToMany
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to-many.js#L36) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L39)
Many-to-many association with a join table. Many-to-many association with a join table.
When the join table has additional attributes, these can be passed in the options object: When the join table has additional attributes, these can be passed in the options object:
...@@ -29,7 +29,7 @@ In the API reference below, replace `Assocation(s)` with the actual name of your ...@@ -29,7 +29,7 @@ In the API reference below, replace `Assocation(s)` with the actual name of your
<a name="getassociations"></a> <a name="getassociations"></a>
## `getAssociations([options])` -> `Promise.<Array.<Instance>>` ## `getAssociations([options])` -> `Promise.<Array.<Instance>>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to-many.js#L200) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L206)
Get everything currently associated with this, using an optional where clause Get everything currently associated with this, using an optional where clause
...@@ -46,7 +46,7 @@ Get everything currently associated with this, using an optional where clause ...@@ -46,7 +46,7 @@ Get everything currently associated with this, using an optional where clause
<a name="setassociations"></a> <a name="setassociations"></a>
## `setAssociations([newAssociations], [options])` -> `Promise` ## `setAssociations([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to-many.js#L210) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L216)
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 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
...@@ -63,7 +63,7 @@ Set the associated models by passing an array of instances or their primary keys ...@@ -63,7 +63,7 @@ Set the associated models by passing an array of instances or their primary keys
<a name="addassociations"></a> <a name="addassociations"></a>
## `addAssociations([newAssociations], [options])` -> `Promise` ## `addAssociations([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to-many.js#L220) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L226)
Associate several instances with this Associate several instances with this
...@@ -80,7 +80,7 @@ Associate several instances with this ...@@ -80,7 +80,7 @@ Associate several instances with this
<a name="addassociation"></a> <a name="addassociation"></a>
## `addAssociation([newAssociation], [options])` -> `Promise` ## `addAssociation([newAssociation], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to-many.js#L230) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L236)
Associate several instances with this Associate several instances with this
...@@ -97,7 +97,7 @@ Associate several instances with this ...@@ -97,7 +97,7 @@ Associate several instances with this
<a name="createassociation"></a> <a name="createassociation"></a>
## `createAssociation([values], [options])` -> `Promise` ## `createAssociation([values], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to-many.js#L239) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L245)
Create a new instance of the associated model and associate it with this. Create a new instance of the associated model and associate it with this.
...@@ -113,7 +113,7 @@ Create a new instance of the associated model and associate it with this. ...@@ -113,7 +113,7 @@ Create a new instance of the associated model and associate it with this.
<a name="removeassociation"></a> <a name="removeassociation"></a>
## `removeAssociation([oldAssociated], [options])` -> `Promise` ## `removeAssociation([oldAssociated], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to-many.js#L248) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L254)
Un-associate the instance Un-associate the instance
...@@ -129,7 +129,7 @@ Un-associate the instance ...@@ -129,7 +129,7 @@ Un-associate the instance
<a name="removeassociations"></a> <a name="removeassociations"></a>
## `removeAssociations([oldAssociated], [options])` -> `Promise` ## `removeAssociations([oldAssociated], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to-many.js#L257) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L263)
Un-associate several instances Un-associate several instances
...@@ -145,7 +145,7 @@ Un-associate several instances ...@@ -145,7 +145,7 @@ Un-associate several instances
<a name="hasassociation"></a> <a name="hasassociation"></a>
## `hasAssociation([instance], [options])` -> `Promise` ## `hasAssociation([instance], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to-many.js#L266) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L272)
Check if an instance is associated with this. Check if an instance is associated with this.
...@@ -161,7 +161,7 @@ Check if an instance is associated with this. ...@@ -161,7 +161,7 @@ Check if an instance is associated with this.
<a name="hasassociations"></a> <a name="hasassociations"></a>
## `hasAssociations([instances], [options])` -> `Promise` ## `hasAssociations([instances], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to-many.js#L275) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L281)
Check if all instances are associated with this. Check if all instances are associated with this.
...@@ -175,4 +175,21 @@ Check if all instances are associated with this. ...@@ -175,4 +175,21 @@ Check if all instances are associated with this.
*** ***
<a name="countassociations"></a>
## `countAssociations([options])` -> `Promise.<Int>`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to-many.js#L291)
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 &#124; Boolean | Apply a scope on the related model, or remove its default scope by passing false |
***
_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 <a href="irc://irc.freenode.net/#sequelizejs">IRC</a>, 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](http://usejsdoc.org) and [dox](https://github.com/tj/dox)_ _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 <a href="irc://irc.freenode.net/#sequelizejs">IRC</a>, 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](http://usejsdoc.org) and [dox](https://github.com/tj/dox)_
\ No newline at end of file
<a name="belongsto"></a> <a name="belongsto"></a>
# Mixin BelongsTo # Mixin BelongsTo
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to.js#L17) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to.js#L17)
One-to-one association One-to-one 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()`. 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()`.
*** ***
<a name="getassociation"></a> <a name="getassociation"></a>
## `getAssociation([options])` -> `Promise.<Instance>` ## `getAssociation([options])` -> `Promise.<Instance>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to.js#L81) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to.js#L82)
Get the associated instance Get the associated instance
...@@ -19,14 +19,14 @@ Get the associated instance ...@@ -19,14 +19,14 @@ Get the associated instance
| Name | Type | Description | | Name | Type | Description |
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| [options] | Object | | | [options] | Object | |
| [options.scope] | String &#124; Boolean | Apply a scope on the related model, or remove its default scope by passing false | | [options.scope] | String &#124; Boolean | Apply a scope on the related model, or remove its default scope by passing false. |
*** ***
<a name="setassociation"></a> <a name="setassociation"></a>
## `setAssociation([newAssociations], [options])` -> `Promise` ## `setAssociation([newAssociation], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to.js#L91) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to.js#L92)
Set the associated model Set the associated model
...@@ -34,7 +34,7 @@ Set the associated model ...@@ -34,7 +34,7 @@ Set the associated model
| Name | Type | Description | | Name | Type | Description |
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| [newAssociations] | Instance &#124; String &#124; Number | An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations. | | [newAssociation] | Instance &#124; String &#124; Number | An instance or the primary key of an instance to associate with this. Pass `null` or `undefined` to remove the association. |
| [options] | Object | Options passed to `this.save` | | [options] | Object | Options passed to `this.save` |
| [options.save=true] | Boolean | Skip saving this after setting the foreign key if false. | | [options.save=true] | Boolean | Skip saving this after setting the foreign key if false. |
...@@ -43,7 +43,7 @@ Set the associated model ...@@ -43,7 +43,7 @@ Set the associated model
<a name="createassociation"></a> <a name="createassociation"></a>
## `createAssociation([values], [options])` -> `Promise` ## `createAssociation([values], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/belongs-to.js#L100) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/belongs-to.js#L101)
Create a new instance of the associated model and associate it with this. Create a new instance of the associated model and associate it with this.
......
<a name="hasmany"></a> <a name="hasmany"></a>
# Mixin HasMany # Mixin HasMany
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-many.js#L17) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L17)
One-to-many association 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()`. 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()`.
...@@ -10,7 +10,7 @@ In the API reference below, replace `Assocation(s)` with the actual name of your ...@@ -10,7 +10,7 @@ In the API reference below, replace `Assocation(s)` with the actual name of your
<a name="getassociations"></a> <a name="getassociations"></a>
## `getAssociations([options])` -> `Promise.<Array.<Instance>>` ## `getAssociations([options])` -> `Promise.<Array.<Instance>>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-many.js#L84) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L103)
Get everything currently associated with this, using an optional where clause Get everything currently associated with this, using an optional where clause
...@@ -27,7 +27,7 @@ Get everything currently associated with this, using an optional where clause ...@@ -27,7 +27,7 @@ Get everything currently associated with this, using an optional where clause
<a name="setassociations"></a> <a name="setassociations"></a>
## `setAssociations([newAssociations], [options])` -> `Promise` ## `setAssociations([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-many.js#L94) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L113)
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 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
...@@ -44,7 +44,7 @@ Set the associated models by passing an array of instances or their primary keys ...@@ -44,7 +44,7 @@ Set the associated models by passing an array of instances or their primary keys
<a name="addassociations"></a> <a name="addassociations"></a>
## `addAssociations([newAssociations], [options])` -> `Promise` ## `addAssociations([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-many.js#L104) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L123)
Associate several instances with this Associate several instances with this
...@@ -61,7 +61,7 @@ Associate several instances with this ...@@ -61,7 +61,7 @@ Associate several instances with this
<a name="addassociation"></a> <a name="addassociation"></a>
## `addAssociation([newAssociation], [options])` -> `Promise` ## `addAssociation([newAssociation], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-many.js#L114) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L133)
Associate several instances with this Associate several instances with this
...@@ -78,7 +78,7 @@ Associate several instances with this ...@@ -78,7 +78,7 @@ Associate several instances with this
<a name="createassociation"></a> <a name="createassociation"></a>
## `createAssociation([values], [options])` -> `Promise` ## `createAssociation([values], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-many.js#L123) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L142)
Create a new instance of the associated model and associate it with this. Create a new instance of the associated model and associate it with this.
...@@ -94,7 +94,7 @@ Create a new instance of the associated model and associate it with this. ...@@ -94,7 +94,7 @@ Create a new instance of the associated model and associate it with this.
<a name="removeassociation"></a> <a name="removeassociation"></a>
## `removeAssociation([oldAssociated], [options])` -> `Promise` ## `removeAssociation([oldAssociated], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-many.js#L132) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L151)
Un-associate the instance Un-associate the instance
...@@ -110,7 +110,7 @@ Un-associate the instance ...@@ -110,7 +110,7 @@ Un-associate the instance
<a name="removeassociations"></a> <a name="removeassociations"></a>
## `removeAssociations([oldAssociated], [options])` -> `Promise` ## `removeAssociations([oldAssociated], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-many.js#L141) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L160)
Un-associate several instances Un-associate several instances
...@@ -126,7 +126,7 @@ Un-associate several instances ...@@ -126,7 +126,7 @@ Un-associate several instances
<a name="hasassociation"></a> <a name="hasassociation"></a>
## `hasAssociation([instance], [options])` -> `Promise` ## `hasAssociation([instance], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-many.js#L150) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L169)
Check if an instance is associated with this. Check if an instance is associated with this.
...@@ -142,7 +142,7 @@ Check if an instance is associated with this. ...@@ -142,7 +142,7 @@ Check if an instance is associated with this.
<a name="hasassociations"></a> <a name="hasassociations"></a>
## `hasAssociations([instances], [options])` -> `Promise` ## `hasAssociations([instances], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-many.js#L159) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L178)
Check if all instances are associated with this. Check if all instances are associated with this.
...@@ -156,4 +156,21 @@ Check if all instances are associated with this. ...@@ -156,4 +156,21 @@ Check if all instances are associated with this.
*** ***
<a name="countassociations"></a>
## `countAssociations([options])` -> `Promise.<Int>`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-many.js#L188)
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 &#124; Boolean | Apply a scope on the related model, or remove its default scope by passing false |
***
_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 <a href="irc://irc.freenode.net/#sequelizejs">IRC</a>, 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](http://usejsdoc.org) and [dox](https://github.com/tj/dox)_ _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 <a href="irc://irc.freenode.net/#sequelizejs">IRC</a>, 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](http://usejsdoc.org) and [dox](https://github.com/tj/dox)_
\ No newline at end of file
<a name="hasone"></a> <a name="hasone"></a>
# Mixin HasOne # Mixin HasOne
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-one.js#L16) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-one.js#L16)
One-to-one association One-to-one 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()`. 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()`.
...@@ -10,7 +10,7 @@ In the API reference below, replace `Assocation(s)` with the actual name of your ...@@ -10,7 +10,7 @@ In the API reference below, replace `Assocation(s)` with the actual name of your
<a name="getassociation"></a> <a name="getassociation"></a>
## `getAssociation([options])` -> `Promise.<Instance>` ## `getAssociation([options])` -> `Promise.<Instance>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-one.js#L79) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-one.js#L75)
Get the associated instance Get the associated instance
...@@ -26,7 +26,7 @@ Get the associated instance ...@@ -26,7 +26,7 @@ Get the associated instance
<a name="setassociation"></a> <a name="setassociation"></a>
## `setAssociation([newAssociations], [options])` -> `Promise` ## `setAssociation([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-one.js#L88) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-one.js#L84)
Set the associated model Set the associated model
...@@ -42,7 +42,7 @@ Set the associated model ...@@ -42,7 +42,7 @@ Set the associated model
<a name="createassociation"></a> <a name="createassociation"></a>
## `createAssociation([values], [options])` -> `Promise` ## `createAssociation([values], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/has-one.js#L97) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/has-one.js#L93)
Create a new instance of the associated model and associate it with this. Create a new instance of the associated model and associate it with this.
......
<a name="associations"></a> <a name="associations"></a>
# Mixin Associations # Mixin Associations
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/mixin.js#L88) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/mixin.js#L88)
Creating assocations in sequelize is done by calling one of the belongsTo / hasOne / hasMany functions on a model (the source), and providing another model as the first argument to the function (the target). Creating assocations in sequelize is done by calling one of the belongsTo / hasOne / hasMany functions on a model (the source), and providing another model as the first argument to the function (the target).
* hasOne - adds a foreign key to target * hasOne - adds a foreign key to target
...@@ -80,7 +80,7 @@ Note how we also specified `constraints: false` for profile picture. This is bec ...@@ -80,7 +80,7 @@ Note how we also specified `constraints: false` for profile picture. This is bec
<a name="hasone"></a> <a name="hasone"></a>
## `hasOne(target, [options])` ## `hasOne(target, [options])`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/mixin.js#L130) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/mixin.js#L130)
Creates an association between this (the source) and the provided target. The foreign key is added on the target. Creates an association between this (the source) and the provided target. The foreign key is added on the target.
Example: `User.hasOne(Profile)`. This will add userId to the profile table. Example: `User.hasOne(Profile)`. This will add userId to the profile table.
...@@ -95,7 +95,7 @@ Example: `User.hasOne(Profile)`. This will add userId to the profile table. ...@@ -95,7 +95,7 @@ Example: `User.hasOne(Profile)`. This will add userId to the profile table.
| [options.hooks=false] | boolean | Set to true to run before-/afterDestroy hooks when an associated model is deleted because of a cascade. For example if `User.hasOne(Profile, {onDelete: 'cascade', hooks:true})`, the before-/afterDestroy hooks for profile will be called when a user is deleted. Otherwise the profile will be deleted without invoking any hooks | | [options.hooks=false] | boolean | Set to true to run before-/afterDestroy hooks when an associated model is deleted because of a cascade. For example if `User.hasOne(Profile, {onDelete: 'cascade', hooks:true})`, the before-/afterDestroy hooks for profile will be called when a user is deleted. Otherwise the profile will be deleted without invoking any hooks |
| [options.as] | string | The alias of this model, in singular form. See also the `name` option passed to `sequelize.define`. If you create multiple associations between the same tables, you should provide an alias to be able to distinguish between them. If you provide an alias when creating the assocition, you should provide the same alias when eager loading and when getting assocated models. Defaults to the singularized name of target | | [options.as] | string | The alias of this model, in singular form. See also the `name` option passed to `sequelize.define`. If you create multiple associations between the same tables, you should provide an alias to be able to distinguish between them. If you provide an alias when creating the assocition, you should provide the same alias when eager loading and when getting assocated models. Defaults to the singularized name of target |
| [options.foreignKey] | string &#124; object | The name of the foreign key in the target table or an object representing the type definition for the foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property to set the name of the colum. Defaults to the name of source + primary key of source | | [options.foreignKey] | string &#124; object | The name of the foreign key in the target table or an object representing the type definition for the foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property to set the name of the colum. Defaults to the name of source + primary key of source |
| [options.onDelete='SET&nbsp;NULL'] | string | | | [options.onDelete='SET&nbsp;NULL &#124; CASCADE'] | string | SET NULL if foreignKey allows nulls, CASCADE if otherwise |
| [options.onUpdate='CASCADE'] | string | | | [options.onUpdate='CASCADE'] | string | |
| [options.constraints=true] | boolean | Should on update and on delete constraints be enabled on the foreign key. | | [options.constraints=true] | boolean | Should on update and on delete constraints be enabled on the foreign key. |
...@@ -104,7 +104,7 @@ Example: `User.hasOne(Profile)`. This will add userId to the profile table. ...@@ -104,7 +104,7 @@ Example: `User.hasOne(Profile)`. This will add userId to the profile table.
<a name="belongsto"></a> <a name="belongsto"></a>
## `belongsTo(target, [options])` ## `belongsTo(target, [options])`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/mixin.js#L148) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/mixin.js#L148)
Creates an association between this (the source) and the provided target. The foreign key is added on the source. Creates an association between this (the source) and the provided target. The foreign key is added on the source.
Example: `Profile.belongsTo(User)`. This will add userId to the profile table. Example: `Profile.belongsTo(User)`. This will add userId to the profile table.
...@@ -120,7 +120,7 @@ Example: `Profile.belongsTo(User)`. This will add userId to the profile table. ...@@ -120,7 +120,7 @@ Example: `Profile.belongsTo(User)`. This will add userId to the profile table.
| [options.as] | string | The alias of this model, in singular form. See also the `name` option passed to `sequelize.define`. If you create multiple associations between the same tables, you should provide an alias to be able to distinguish between them. If you provide an alias when creating the association, you should provide the same alias when eager loading and when getting assocated models. Defaults to the singularized name of target | | [options.as] | string | The alias of this model, in singular form. See also the `name` option passed to `sequelize.define`. If you create multiple associations between the same tables, you should provide an alias to be able to distinguish between them. If you provide an alias when creating the association, you should provide the same alias when eager loading and when getting assocated models. Defaults to the singularized name of target |
| [options.foreignKey] | string &#124; object | The name of the foreign key in the source table or an object representing the type definition for the foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property to set the name of the column. Defaults to the name of target + primary key of target | | [options.foreignKey] | string &#124; object | The name of the foreign key in the source table or an object representing the type definition for the foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property to set the name of the column. Defaults to the name of target + primary key of target |
| [options.targetKey] | string | The name of the field to use as the key for the association in the target table. Defaults to the primary key of the target table | | [options.targetKey] | string | The name of the field to use as the key for the association in the target table. Defaults to the primary key of the target table |
| [options.onDelete='SET&nbsp;NULL'] | string | | | [options.onDelete='SET&nbsp;NULL &#124; NO&nbsp;ACTION'] | string | SET NULL if foreignKey allows nulls, NO ACTION if otherwise |
| [options.onUpdate='CASCADE'] | string | | | [options.onUpdate='CASCADE'] | string | |
| [options.constraints=true] | boolean | Should on update and on delete constraints be enabled on the foreign key. | | [options.constraints=true] | boolean | Should on update and on delete constraints be enabled on the foreign key. |
...@@ -129,7 +129,7 @@ Example: `Profile.belongsTo(User)`. This will add userId to the profile table. ...@@ -129,7 +129,7 @@ Example: `Profile.belongsTo(User)`. This will add userId to the profile table.
<a name="hasmany"></a> <a name="hasmany"></a>
## `hasMany(target, [options])` ## `hasMany(target, [options])`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/mixin.js#L208) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/mixin.js#L204)
Create an association that is either 1:m or n:m. Create an association that is either 1:m or n:m.
```js ```js
...@@ -181,14 +181,10 @@ user.getProjects().then(function (projects) { ...@@ -181,14 +181,10 @@ user.getProjects().then(function (projects) {
| target | Model | | | target | Model | |
| [options] | object | | | [options] | object | |
| [options.hooks=false] | boolean | Set to true to run before-/afterDestroy hooks when an associated model is deleted because of a cascade. For example if `User.hasOne(Profile, {onDelete: 'cascade', hooks:true})`, the before-/afterDestroy hooks for profile will be called when a user is deleted. Otherwise the profile will be deleted without invoking any hooks | | [options.hooks=false] | boolean | Set to true to run before-/afterDestroy hooks when an associated model is deleted because of a cascade. For example if `User.hasOne(Profile, {onDelete: 'cascade', hooks:true})`, the before-/afterDestroy hooks for profile will be called when a user is deleted. Otherwise the profile will be deleted without invoking any hooks |
| [options.through] | Model &#124; string &#124; object | The name of the table that is used to join source and target in n:m associations. Can also be a sequelize model if you want to define the junction table yourself and add extra attributes to it. |
| [options.through.model] | Model | The model used to join both sides of the N:M association. |
| [options.through.scope] | object | A key/value set that will be used for association create and find defaults on the through model. (Remember to add the attributes to the through model) |
| [options.through.unique=true] | boolean | If true a unique key will be generated from the foreign keys used (might want to turn this off and create specific unique keys when using scopes) |
| [options.as] | string &#124; object | The alias of this model. If you provide a string, it should be plural, and will be singularized using node.inflection. If you want to control the singular version yourself, provide an object with `plural` and `singular` keys. See also the `name` option passed to `sequelize.define`. If you create multiple associations between the same tables, you should provide an alias to be able to distinguish between them. If you provide an alias when creating the assocition, you should provide the same alias when eager loading and when getting assocated models. Defaults to the pluralized name of target | | [options.as] | string &#124; object | The alias of this model. If you provide a string, it should be plural, and will be singularized using node.inflection. If you want to control the singular version yourself, provide an object with `plural` and `singular` keys. See also the `name` option passed to `sequelize.define`. If you create multiple associations between the same tables, you should provide an alias to be able to distinguish between them. If you provide an alias when creating the assocition, you should provide the same alias when eager loading and when getting assocated models. Defaults to the pluralized name of target |
| [options.foreignKey] | string &#124; object | The name of the foreign key in the target table / join table or an object representing the type definition for the foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property to set the name of the colum. Defaults to the name of source + primary key of source | | [options.foreignKey] | string &#124; object | The name of the foreign key in the target table / join table or an object representing the type definition for the foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property to set the name of the colum. Defaults to the name of source + primary key of source |
| [options.scope] | object | A key/value set that will be used for association create and find defaults on the target. (sqlite not supported for N:M) | | [options.scope] | object | A key/value set that will be used for association create and find defaults on the target. (sqlite not supported for N:M) |
| [options.onDelete='SET&nbsp;NULL &#124; CASCADE'] | string | Cascade if this is a n:m, and set null if it is a 1:m | | [options.onDelete='SET&nbsp;NULL &#124; CASCADE'] | string | SET NULL if foreignKey allows nulls, CASCADE if otherwise |
| [options.onUpdate='CASCADE'] | string | | | [options.onUpdate='CASCADE'] | string | |
| [options.constraints=true] | boolean | Should on update and on delete constraints be enabled on the foreign key. | | [options.constraints=true] | boolean | Should on update and on delete constraints be enabled on the foreign key. |
...@@ -197,7 +193,7 @@ user.getProjects().then(function (projects) { ...@@ -197,7 +193,7 @@ user.getProjects().then(function (projects) {
<a name="belongstomany"></a> <a name="belongstomany"></a>
## `belongsToMany(target, [options])` ## `belongsToMany(target, [options])`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/associations/mixin.js#L287) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/associations/mixin.js#L283)
Create an N:M association with a join table Create an N:M association with a join table
```js ```js
...@@ -252,6 +248,7 @@ user.getProjects().then(function (projects) { ...@@ -252,6 +248,7 @@ user.getProjects().then(function (projects) {
| [options.foreignKey] | string &#124; object | The name of the foreign key in the join table (representing the source model) or an object representing the type definition for the foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property to set the name of the colum. Defaults to the name of source + primary key of source | | [options.foreignKey] | string &#124; object | The name of the foreign key in the join table (representing the source model) or an object representing the type definition for the foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property to set the name of the colum. Defaults to the name of source + primary key of source |
| [options.otherKey] | string &#124; object | The name of the foreign key in the join table (representing the target model) or an object representing the type definition for the other column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property to set the name of the colum. Defaults to the name of target + primary key of target | | [options.otherKey] | string &#124; object | The name of the foreign key in the join table (representing the target model) or an object representing the type definition for the other column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property to set the name of the colum. Defaults to the name of target + primary key of target |
| [options.scope] | object | A key/value set that will be used for association create and find defaults on the target. (sqlite not supported for N:M) | | [options.scope] | object | A key/value set that will be used for association create and find defaults on the target. (sqlite not supported for N:M) |
| [options.timestamps=sequelize.options.timestamps] | boolean | Should the join model have timestamps |
| [options.onDelete='SET&nbsp;NULL &#124; CASCADE'] | string | Cascade if this is a n:m, and set null if it is a 1:m | | [options.onDelete='SET&nbsp;NULL &#124; CASCADE'] | string | Cascade if this is a n:m, and set null if it is a 1:m |
| [options.onUpdate='CASCADE'] | string | | | [options.onUpdate='CASCADE'] | string | |
| [options.constraints=true] | boolean | Should on update and on delete constraints be enabled on the foreign key. | | [options.constraints=true] | boolean | Should on update and on delete constraints be enabled on the foreign key. |
......
<a name="datatypes"></a> <a name="datatypes"></a>
# Class DataTypes # Class DataTypes
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L39) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L41)
A convenience class holding commonly used data types. The datatypes are used when definining a new model using `Sequelize.define`, like this: A convenience class holding commonly used data types. The datatypes are used when defining a new model using `Sequelize.define`, like this:
```js ```js
sequelize.define('model', { sequelize.define('model', {
column: DataTypes.INTEGER column: DataTypes.INTEGER
...@@ -33,7 +33,7 @@ sequelize.define('model', { ...@@ -33,7 +33,7 @@ sequelize.define('model', {
<a name="string"></a> <a name="string"></a>
## `STRING()` ## `STRING()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L65) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L67)
A variable length string. Default length 255 A variable length string. Default length 255
Available properties: `BINARY` Available properties: `BINARY`
...@@ -43,7 +43,7 @@ Available properties: `BINARY` ...@@ -43,7 +43,7 @@ Available properties: `BINARY`
<a name="char"></a> <a name="char"></a>
## `CHAR()` ## `CHAR()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L98) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L112)
A fixed length string. Default length 255 A fixed length string. Default length 255
Available properties: `BINARY` Available properties: `BINARY`
...@@ -53,14 +53,14 @@ Available properties: `BINARY` ...@@ -53,14 +53,14 @@ Available properties: `BINARY`
<a name="text"></a> <a name="text"></a>
## `TEXT()` ## `TEXT()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L118) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L132)
An (un)limited length text column. Available lengths: `tiny`, `medium`, `long` An (un)limited length text column. Available lengths: `tiny`, `medium`, `long`
*** ***
<a name="integer"></a> <a name="integer"></a>
## `INTEGER()` ## `INTEGER()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L193) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L221)
A 32 bit integer. A 32 bit integer.
Available properties: `UNSIGNED`, `ZEROFILL` Available properties: `UNSIGNED`, `ZEROFILL`
...@@ -70,7 +70,7 @@ Available properties: `UNSIGNED`, `ZEROFILL` ...@@ -70,7 +70,7 @@ Available properties: `UNSIGNED`, `ZEROFILL`
<a name="bigint"></a> <a name="bigint"></a>
## `BIGINT()` ## `BIGINT()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L212) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L247)
A 64 bit integer. A 64 bit integer.
Available properties: `UNSIGNED`, `ZEROFILL` Available properties: `UNSIGNED`, `ZEROFILL`
...@@ -80,7 +80,7 @@ Available properties: `UNSIGNED`, `ZEROFILL` ...@@ -80,7 +80,7 @@ Available properties: `UNSIGNED`, `ZEROFILL`
<a name="float"></a> <a name="float"></a>
## `FLOAT()` ## `FLOAT()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L230) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L272)
Floating point number (4-byte precision). Accepts one or two arguments for precision Floating point number (4-byte precision). Accepts one or two arguments for precision
Available properties: `UNSIGNED`, `ZEROFILL` Available properties: `UNSIGNED`, `ZEROFILL`
...@@ -90,7 +90,7 @@ Available properties: `UNSIGNED`, `ZEROFILL` ...@@ -90,7 +90,7 @@ Available properties: `UNSIGNED`, `ZEROFILL`
<a name="real"></a> <a name="real"></a>
## `REAL()` ## `REAL()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L249) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L298)
Floating point number (4-byte precision). Accepts one or two arguments for precision Floating point number (4-byte precision). Accepts one or two arguments for precision
Available properties: `UNSIGNED`, `ZEROFILL` Available properties: `UNSIGNED`, `ZEROFILL`
...@@ -100,7 +100,7 @@ Available properties: `UNSIGNED`, `ZEROFILL` ...@@ -100,7 +100,7 @@ Available properties: `UNSIGNED`, `ZEROFILL`
<a name="double"></a> <a name="double"></a>
## `DOUBLE()` ## `DOUBLE()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L268) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L317)
Floating point number (8-byte precision). Accepts one or two arguments for precision Floating point number (8-byte precision). Accepts one or two arguments for precision
Available properties: `UNSIGNED`, `ZEROFILL` Available properties: `UNSIGNED`, `ZEROFILL`
...@@ -110,7 +110,7 @@ Available properties: `UNSIGNED`, `ZEROFILL` ...@@ -110,7 +110,7 @@ Available properties: `UNSIGNED`, `ZEROFILL`
<a name="decimal"></a> <a name="decimal"></a>
## `DECIMAL()` ## `DECIMAL()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L287) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L336)
Decimal number. Accepts one or two arguments for precision Decimal number. Accepts one or two arguments for precision
Available properties: `UNSIGNED`, `ZEROFILL` Available properties: `UNSIGNED`, `ZEROFILL`
...@@ -120,63 +120,63 @@ Available properties: `UNSIGNED`, `ZEROFILL` ...@@ -120,63 +120,63 @@ Available properties: `UNSIGNED`, `ZEROFILL`
<a name="boolean"></a> <a name="boolean"></a>
## `BOOLEAN()` ## `BOOLEAN()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L310) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L366)
A boolean / tinyint column, depending on dialect A boolean / tinyint column, depending on dialect
*** ***
<a name="time"></a> <a name="time"></a>
## `TIME()` ## `TIME()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L326) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L389)
A time column A time column
*** ***
<a name="date"></a> <a name="date"></a>
## `DATE()` ## `DATE()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L341) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L404)
A datetime column A datetime column
*** ***
<a name="dateonly"></a> <a name="dateonly"></a>
## `DATEONLY()` ## `DATEONLY()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L357) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L426)
A date only column A date only column
*** ***
<a name="hstore"></a> <a name="hstore"></a>
## `HSTORE()` ## `HSTORE()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L373) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L442)
A key / value column. Only available in postgres. A key / value column. Only available in postgres.
*** ***
<a name="json"></a> <a name="json"></a>
## `JSON()` ## `JSON()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L385) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L461)
A JSON string column. Only available in postgres. A JSON string column. Only available in postgres.
*** ***
<a name="jsonb"></a> <a name="jsonb"></a>
## `JSONB()` ## `JSONB()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L397) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L476)
A pre-processed JSON data column. Only available in postgres. A pre-processed JSON data column. Only available in postgres.
*** ***
<a name="now"></a> <a name="now"></a>
## `NOW()` ## `NOW()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L409) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L488)
A default value of the current timestamp A default value of the current timestamp
*** ***
<a name="blob"></a> <a name="blob"></a>
## `BLOB()` ## `BLOB()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L423) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L502)
Binary storage. Available lengths: `tiny`, `medium`, `long` Binary storage. Available lengths: `tiny`, `medium`, `long`
...@@ -184,7 +184,7 @@ Binary storage. Available lengths: `tiny`, `medium`, `long` ...@@ -184,7 +184,7 @@ Binary storage. Available lengths: `tiny`, `medium`, `long`
<a name="range"></a> <a name="range"></a>
## `RANGE()` ## `RANGE()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L453) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L539)
Range types are data types representing a range of values of some element type (called the range's subtype). Range types are data types representing a range of values of some element type (called the range's subtype).
Only available in postgres. Only available in postgres.
See {@link http://www.postgresql.org/docs/9.4/static/rangetypes.html|Postgres documentation} for more details See {@link http://www.postgresql.org/docs/9.4/static/rangetypes.html|Postgres documentation} for more details
...@@ -193,34 +193,34 @@ See {@link http://www.postgresql.org/docs/9.4/static/rangetypes.html|Postgres do ...@@ -193,34 +193,34 @@ See {@link http://www.postgresql.org/docs/9.4/static/rangetypes.html|Postgres do
<a name="uuid"></a> <a name="uuid"></a>
## `UUID()` ## `UUID()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L482) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L583)
A column storing a unique univeral identifier. Use with `UUIDV1` or `UUIDV4` for default values. A column storing a unique univeral identifier. Use with `UUIDV1` or `UUIDV4` for default values.
*** ***
<a name="uuidv1"></a> <a name="uuidv1"></a>
## `UUIDV1()` ## `UUIDV1()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L495) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L603)
A default unique universal identifier generated following the UUID v1 standard A default unique universal identifier generated following the UUID v1 standard
*** ***
<a name="uuidv4"></a> <a name="uuidv4"></a>
## `UUIDV4()` ## `UUIDV4()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L508) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L623)
A default unique universal identifier generated following the UUID v2 standard A default unique universal identifier generated following the UUID v2 standard
*** ***
<a name="virtual"></a> <a name="virtual"></a>
## `VIRTUAL()` ## `VIRTUAL()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L543) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L679)
A virtual value that is not stored in the DB. This could for example be useful if you want to provide a default value in your model that is returned to the user but not stored in the DB. A virtual value that is not stored in the DB. This could for example be useful if you want to provide a default value in your model that is returned to the user but not stored in the DB.
You could also use it to validate a value before permuting and storing it. Checking password length before hashing it for example: You could also use it to validate a value before permuting and storing it. Checking password length before hashing it for example:
```js ```js
sequelize.define('user', { sequelize.define('user', {
password_hash: DataTypes.STRING password_hash: DataTypes.STRING,
password: { password: {
type: DataTypes.VIRTUAL, type: DataTypes.VIRTUAL,
set: function (val) { set: function (val) {
...@@ -237,6 +237,20 @@ sequelize.define('user', { ...@@ -237,6 +237,20 @@ sequelize.define('user', {
} }
}) })
``` ```
VIRTUAL also takes a return type and dependency fields as arguments
If a virtual attribute is present in `attributes` it will automatically pull in the extra fields aswell.
Return type is mostly usefull for setups that rely on types like GraphQL.
```js
{
active: {
type: new DataTypes.VIRTUAL(DataTypes.BOOLEAN, ['createdAt']),
get: function() {
return this.get('createdAt') > Date.now() - (7 * 24 * 60 * 60 * 1000)
}
}
}
In the above code the password is stored plainly in the password field so it can be validated, but is never stored in the DB. In the above code the password is stored plainly in the password field so it can be validated, but is never stored in the DB.
__Aliases:__ NONE __Aliases:__ NONE
...@@ -244,7 +258,7 @@ __Aliases:__ NONE ...@@ -244,7 +258,7 @@ __Aliases:__ NONE
<a name="enum"></a> <a name="enum"></a>
## `ENUM()` ## `ENUM()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L556) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L695)
An enumeration. `DataTypes.ENUM('value', 'another value')`. An enumeration. `DataTypes.ENUM('value', 'another value')`.
...@@ -252,7 +266,7 @@ An enumeration. `DataTypes.ENUM('value', 'another value')`. ...@@ -252,7 +266,7 @@ An enumeration. `DataTypes.ENUM('value', 'another value')`.
<a name="array"></a> <a name="array"></a>
## `ARRAY()` ## `ARRAY()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/data-types.js#L573) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/data-types.js#L719)
An array of `type`, e.g. `DataTypes.ARRAY(DataTypes.DECIMAL)`. Only available in postgres. An array of `type`, e.g. `DataTypes.ARRAY(DataTypes.DECIMAL)`. Only available in postgres.
*** ***
......
<a name="deferrable"></a> <a name="deferrable"></a>
## `Deferrable()` -> `object` ## `Deferrable()` -> `object`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/deferrable.js#L39) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/deferrable.js#L39)
A collection of properties related to deferrable constraints. It can be used to A collection of properties related to deferrable constraints. It can be used to
make foreign key constraints deferrable and to set the constaints within a make foreign key constraints deferrable and to set the constaints within a
transaction. This is only supported in PostgreSQL. transaction. This is only supported in PostgreSQL.
...@@ -36,7 +36,7 @@ sequelize.transaction({ ...@@ -36,7 +36,7 @@ sequelize.transaction({
<a name="initially_deferred"></a> <a name="initially_deferred"></a>
## `INITIALLY_DEFERRED()` ## `INITIALLY_DEFERRED()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/deferrable.js#L59) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/deferrable.js#L59)
A property that will defer constraints checks to the end of transactions. A property that will defer constraints checks to the end of transactions.
...@@ -44,7 +44,7 @@ A property that will defer constraints checks to the end of transactions. ...@@ -44,7 +44,7 @@ A property that will defer constraints checks to the end of transactions.
<a name="initially_immediate"></a> <a name="initially_immediate"></a>
## `INITIALLY_IMMEDIATE()` ## `INITIALLY_IMMEDIATE()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/deferrable.js#L76) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/deferrable.js#L76)
A property that will trigger the constraint checks immediately A property that will trigger the constraint checks immediately
...@@ -52,7 +52,7 @@ A property that will trigger the constraint checks immediately ...@@ -52,7 +52,7 @@ A property that will trigger the constraint checks immediately
<a name="not"></a> <a name="not"></a>
## `NOT()` ## `NOT()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/deferrable.js#L95) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/deferrable.js#L95)
A property that will set the constraints to not deferred. This is A property that will set the constraints to not deferred. This is
the default in PostgreSQL and it make it impossible to dynamically the default in PostgreSQL and it make it impossible to dynamically
defer the constraints within a transaction. defer the constraints within a transaction.
...@@ -62,7 +62,7 @@ defer the constraints within a transaction. ...@@ -62,7 +62,7 @@ defer the constraints within a transaction.
<a name="set_deferred"></a> <a name="set_deferred"></a>
## `SET_DEFERRED(constraints)` ## `SET_DEFERRED(constraints)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/deferrable.js#L114) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/deferrable.js#L114)
A property that will trigger an additional query at the beginning of a A property that will trigger an additional query at the beginning of a
transaction which sets the constraints to deferred. transaction which sets the constraints to deferred.
...@@ -78,7 +78,7 @@ transaction which sets the constraints to deferred. ...@@ -78,7 +78,7 @@ transaction which sets the constraints to deferred.
<a name="set_immediate"></a> <a name="set_immediate"></a>
## `SET_IMMEDIATE(constraints)` ## `SET_IMMEDIATE(constraints)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/deferrable.js#L135) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/deferrable.js#L135)
A property that will trigger an additional query at the beginning of a A property that will trigger an additional query at the beginning of a
transaction which sets the constraints to immediately. transaction which sets the constraints to immediately.
......
<a name="errors"></a> <a name="errors"></a>
# Class Errors # Class Errors
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L11) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L11)
Sequelize provides a host of custom error classes, to allow you to do easier debugging. All of these errors are exposed on the sequelize object and the sequelize constructor. Sequelize provides a host of custom error classes, to allow you to do easier debugging. All of these errors are exposed on the sequelize object and the sequelize constructor.
All sequelize errors inherit from the base JS error object. All sequelize errors inherit from the base JS error object.
...@@ -9,7 +9,7 @@ All sequelize errors inherit from the base JS error object. ...@@ -9,7 +9,7 @@ All sequelize errors inherit from the base JS error object.
<a name="baseerror"></a> <a name="baseerror"></a>
## `new BaseError()` ## `new BaseError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L20) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L20)
The Base Error all Sequelize Errors inherit from. The Base Error all Sequelize Errors inherit from.
__Aliases:__ Error __Aliases:__ Error
...@@ -18,7 +18,7 @@ __Aliases:__ Error ...@@ -18,7 +18,7 @@ __Aliases:__ Error
<a name="validationerror"></a> <a name="validationerror"></a>
## `new ValidationError(message, [errors])` ## `new ValidationError(message, [errors])`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L41) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L41)
Validation Error. Thrown when the sequelize validation has failed. The error contains an `errors` property, Validation Error. Thrown when the sequelize validation has failed. The error contains an `errors` property,
which is an array with 1 or more ValidationErrorItems, one for each validation that failed. which is an array with 1 or more ValidationErrorItems, one for each validation that failed.
...@@ -37,14 +37,14 @@ __Extends:__ BaseError ...@@ -37,14 +37,14 @@ __Extends:__ BaseError
<a name="errors"></a> <a name="errors"></a>
## `errors` ## `errors`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L49) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L49)
An array of ValidationErrorItems An array of ValidationErrorItems
*** ***
<a name="get"></a> <a name="get"></a>
## `get(path)` ## `get(path)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L70) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L70)
Gets all validation error items for the path / field specified. Gets all validation error items for the path / field specified.
...@@ -59,7 +59,7 @@ Gets all validation error items for the path / field specified. ...@@ -59,7 +59,7 @@ Gets all validation error items for the path / field specified.
<a name="databaseerror"></a> <a name="databaseerror"></a>
## `new DatabaseError()` ## `new DatabaseError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L84) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L84)
A base class for all database related errors. A base class for all database related errors.
__Extends:__ BaseError __Extends:__ BaseError
...@@ -68,49 +68,49 @@ __Extends:__ BaseError ...@@ -68,49 +68,49 @@ __Extends:__ BaseError
<a name="parent"></a> <a name="parent"></a>
## `parent` ## `parent`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L92) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L92)
The database specific error which triggered this one The database specific error which triggered this one
*** ***
<a name="sql"></a> <a name="sql"></a>
## `sql` ## `sql`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L98) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L98)
The SQL that triggered the error The SQL that triggered the error
*** ***
<a name="message"></a> <a name="message"></a>
## `message()` ## `message()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L104) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L104)
The message from the DB. The message from the DB.
*** ***
<a name="fields"></a> <a name="fields"></a>
## `fields()` ## `fields()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L109) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L109)
The fields of the unique constraint The fields of the unique constraint
*** ***
<a name="value"></a> <a name="value"></a>
## `value()` ## `value()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L114) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L114)
The value(s) which triggered the error The value(s) which triggered the error
*** ***
<a name="index"></a> <a name="index"></a>
## `index()` ## `index()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L119) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L119)
The name of the index that triggered the error The name of the index that triggered the error
*** ***
<a name="timeouterror"></a> <a name="timeouterror"></a>
## `new TimeoutError()` ## `new TimeoutError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L127) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L127)
Thrown when a database query times out because of a deadlock Thrown when a database query times out because of a deadlock
__Extends:__ DatabaseError __Extends:__ DatabaseError
...@@ -119,7 +119,7 @@ __Extends:__ DatabaseError ...@@ -119,7 +119,7 @@ __Extends:__ DatabaseError
<a name="uniqueconstrainterror"></a> <a name="uniqueconstrainterror"></a>
## `new UniqueConstraintError()` ## `new UniqueConstraintError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L138) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L138)
Thrown when a unique constraint is violated in the database Thrown when a unique constraint is violated in the database
__Extends:__ DatabaseError __Extends:__ DatabaseError
...@@ -128,7 +128,7 @@ __Extends:__ DatabaseError ...@@ -128,7 +128,7 @@ __Extends:__ DatabaseError
<a name="foreignkeyconstrainterror"></a> <a name="foreignkeyconstrainterror"></a>
## `new ForeignKeyConstraintError()` ## `new ForeignKeyConstraintError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L157) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L157)
Thrown when a foreign key constraint is violated in the database Thrown when a foreign key constraint is violated in the database
__Extends:__ DatabaseError __Extends:__ DatabaseError
...@@ -137,7 +137,7 @@ __Extends:__ DatabaseError ...@@ -137,7 +137,7 @@ __Extends:__ DatabaseError
<a name="exclusionconstrainterror"></a> <a name="exclusionconstrainterror"></a>
## `new ExclusionConstraintError()` ## `new ExclusionConstraintError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L177) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L177)
Thrown when an exclusion constraint is violated in the database Thrown when an exclusion constraint is violated in the database
__Extends:__ DatabaseError __Extends:__ DatabaseError
...@@ -146,7 +146,7 @@ __Extends:__ DatabaseError ...@@ -146,7 +146,7 @@ __Extends:__ DatabaseError
<a name="validationerroritem"></a> <a name="validationerroritem"></a>
## `new ValidationErrorItem(message, type, path, value)` ## `new ValidationErrorItem(message, type, path, value)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L201) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L201)
Validation Error Item Validation Error Item
Instances of this class are included in the `ValidationError.errors` property. Instances of this class are included in the `ValidationError.errors` property.
...@@ -165,7 +165,7 @@ Instances of this class are included in the `ValidationError.errors` property. ...@@ -165,7 +165,7 @@ Instances of this class are included in the `ValidationError.errors` property.
<a name="connectionerror"></a> <a name="connectionerror"></a>
## `new ConnectionError()` ## `new ConnectionError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L213) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L213)
A base class for all connection related errors. A base class for all connection related errors.
__Extends:__ BaseError __Extends:__ BaseError
...@@ -174,14 +174,14 @@ __Extends:__ BaseError ...@@ -174,14 +174,14 @@ __Extends:__ BaseError
<a name="parent"></a> <a name="parent"></a>
## `parent` ## `parent`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L220) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L220)
The connection specific error which triggered this one The connection specific error which triggered this one
*** ***
<a name="connectionrefusederror"></a> <a name="connectionrefusederror"></a>
## `new ConnectionRefusedError()` ## `new ConnectionRefusedError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L230) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L230)
Thrown when a connection to a database is refused Thrown when a connection to a database is refused
__Extends:__ ConnectionError __Extends:__ ConnectionError
...@@ -190,7 +190,7 @@ __Extends:__ ConnectionError ...@@ -190,7 +190,7 @@ __Extends:__ ConnectionError
<a name="accessdeniederror"></a> <a name="accessdeniederror"></a>
## `new AccessDeniedError()` ## `new AccessDeniedError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L241) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L241)
Thrown when a connection to a database is refused due to insufficient privileges Thrown when a connection to a database is refused due to insufficient privileges
__Extends:__ ConnectionError __Extends:__ ConnectionError
...@@ -199,7 +199,7 @@ __Extends:__ ConnectionError ...@@ -199,7 +199,7 @@ __Extends:__ ConnectionError
<a name="hostnotfounderror"></a> <a name="hostnotfounderror"></a>
## `new HostNotFoundError()` ## `new HostNotFoundError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L252) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L252)
Thrown when a connection to a database has a hostname that was not found Thrown when a connection to a database has a hostname that was not found
__Extends:__ ConnectionError __Extends:__ ConnectionError
...@@ -208,7 +208,7 @@ __Extends:__ ConnectionError ...@@ -208,7 +208,7 @@ __Extends:__ ConnectionError
<a name="hostnotreachableerror"></a> <a name="hostnotreachableerror"></a>
## `new HostNotReachableError()` ## `new HostNotReachableError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L263) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L263)
Thrown when a connection to a database has a hostname that was not reachable Thrown when a connection to a database has a hostname that was not reachable
__Extends:__ ConnectionError __Extends:__ ConnectionError
...@@ -217,7 +217,7 @@ __Extends:__ ConnectionError ...@@ -217,7 +217,7 @@ __Extends:__ ConnectionError
<a name="invalidconnectionerror"></a> <a name="invalidconnectionerror"></a>
## `new InvalidConnectionError()` ## `new InvalidConnectionError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L274) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L274)
Thrown when a connection to a database has invalid values for any of the connection parameters Thrown when a connection to a database has invalid values for any of the connection parameters
__Extends:__ ConnectionError __Extends:__ ConnectionError
...@@ -226,7 +226,7 @@ __Extends:__ ConnectionError ...@@ -226,7 +226,7 @@ __Extends:__ ConnectionError
<a name="connectiontimedouterror"></a> <a name="connectiontimedouterror"></a>
## `new ConnectionTimedOutError()` ## `new ConnectionTimedOutError()`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/errors.js#L285) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/errors.js#L285)
Thrown when a connection to a database times out Thrown when a connection to a database times out
__Extends:__ ConnectionError __Extends:__ ConnectionError
......
<a name="hooks"></a> <a name="hooks"></a>
# Mixin Hooks # Mixin Hooks
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L39) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L39)
Hooks are function that are called before and after (bulk-) creation/updating/deletion and validation. Hooks can be added to you models in three ways: Hooks are function that are called before and after (bulk-) creation/updating/deletion and validation. Hooks can be added to you models in three ways:
1. By specifying them as options in `sequelize.define` 1. By specifying them as options in `sequelize.define`
...@@ -38,7 +38,7 @@ Model.afterBulkUpdate(function () {}) ...@@ -38,7 +38,7 @@ Model.afterBulkUpdate(function () {})
<a name="addhook"></a> <a name="addhook"></a>
## `addHook(hooktype, [name], fn)` ## `addHook(hooktype, [name], fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L152) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L160)
Add a hook to the model Add a hook to the model
...@@ -56,7 +56,7 @@ __Aliases:__ hook ...@@ -56,7 +56,7 @@ __Aliases:__ hook
<a name="removehook"></a> <a name="removehook"></a>
## `removeHook(hookType, name)` ## `removeHook(hookType, name)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L171) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L179)
Remove hook from the model Remove hook from the model
...@@ -72,7 +72,7 @@ Remove hook from the model ...@@ -72,7 +72,7 @@ Remove hook from the model
<a name="hashook"></a> <a name="hashook"></a>
## `hasHook(hookType)` ## `hasHook(hookType)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L197) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L205)
Check whether the mode has any hooks of this type Check whether the mode has any hooks of this type
...@@ -88,7 +88,7 @@ __Aliases:__ hasHooks ...@@ -88,7 +88,7 @@ __Aliases:__ hasHooks
<a name="beforevalidate"></a> <a name="beforevalidate"></a>
## `beforeValidate(name, fn)` ## `beforeValidate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L210) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L218)
A hook that is run before validation A hook that is run before validation
**Params:** **Params:**
...@@ -103,7 +103,7 @@ A hook that is run before validation ...@@ -103,7 +103,7 @@ A hook that is run before validation
<a name="aftervalidate"></a> <a name="aftervalidate"></a>
## `afterValidate(name, fn)` ## `afterValidate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L217) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L225)
A hook that is run after validation A hook that is run after validation
**Params:** **Params:**
...@@ -118,7 +118,7 @@ A hook that is run after validation ...@@ -118,7 +118,7 @@ A hook that is run after validation
<a name="beforecreate"></a> <a name="beforecreate"></a>
## `beforeCreate(name, fn)` ## `beforeCreate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L224) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L232)
A hook that is run before creating a single instance A hook that is run before creating a single instance
**Params:** **Params:**
...@@ -133,7 +133,7 @@ A hook that is run before creating a single instance ...@@ -133,7 +133,7 @@ A hook that is run before creating a single instance
<a name="aftercreate"></a> <a name="aftercreate"></a>
## `afterCreate(name, fn)` ## `afterCreate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L231) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L239)
A hook that is run after creating a single instance A hook that is run after creating a single instance
**Params:** **Params:**
...@@ -148,7 +148,7 @@ A hook that is run after creating a single instance ...@@ -148,7 +148,7 @@ A hook that is run after creating a single instance
<a name="beforedestroy"></a> <a name="beforedestroy"></a>
## `beforeDestroy(name, fn)` ## `beforeDestroy(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L240) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L248)
A hook that is run before destroying a single instance A hook that is run before destroying a single instance
**Params:** **Params:**
...@@ -164,7 +164,7 @@ __Aliases:__ beforeDelete ...@@ -164,7 +164,7 @@ __Aliases:__ beforeDelete
<a name="afterdestroy"></a> <a name="afterdestroy"></a>
## `afterDestroy(name, fn)` ## `afterDestroy(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L249) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L257)
A hook that is run after destroying a single instance A hook that is run after destroying a single instance
**Params:** **Params:**
...@@ -178,9 +178,39 @@ __Aliases:__ afterDelete ...@@ -178,9 +178,39 @@ __Aliases:__ afterDelete
*** ***
<a name="beforerestore"></a>
## `beforeRestore(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L265)
A hook that is run before restoring a single instance
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| name | String | |
| fn | Function | A callback function that is called with instance, options |
***
<a name="afterrestore"></a>
## `afterRestore(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L273)
A hook that is run after restoring a single instance
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| name | String | |
| fn | Function | A callback function that is called with instance, options |
***
<a name="beforeupdate"></a> <a name="beforeupdate"></a>
## `beforeUpdate(name, fn)` ## `beforeUpdate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L256) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L280)
A hook that is run before updating a single instance A hook that is run before updating a single instance
**Params:** **Params:**
...@@ -195,7 +225,7 @@ A hook that is run before updating a single instance ...@@ -195,7 +225,7 @@ A hook that is run before updating a single instance
<a name="afterupdate"></a> <a name="afterupdate"></a>
## `afterUpdate(name, fn)` ## `afterUpdate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L263) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L287)
A hook that is run after updating a single instance A hook that is run after updating a single instance
**Params:** **Params:**
...@@ -210,7 +240,7 @@ A hook that is run after updating a single instance ...@@ -210,7 +240,7 @@ A hook that is run after updating a single instance
<a name="beforebulkcreate"></a> <a name="beforebulkcreate"></a>
## `beforeBulkCreate(name, fn)` ## `beforeBulkCreate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L270) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L294)
A hook that is run before creating instances in bulk A hook that is run before creating instances in bulk
**Params:** **Params:**
...@@ -225,7 +255,7 @@ A hook that is run before creating instances in bulk ...@@ -225,7 +255,7 @@ A hook that is run before creating instances in bulk
<a name="afterbulkcreate"></a> <a name="afterbulkcreate"></a>
## `afterBulkCreate(name, fn)` ## `afterBulkCreate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L277) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L301)
A hook that is run after creating instances in bulk A hook that is run after creating instances in bulk
**Params:** **Params:**
...@@ -240,7 +270,7 @@ A hook that is run after creating instances in bulk ...@@ -240,7 +270,7 @@ A hook that is run after creating instances in bulk
<a name="beforebulkdestroy"></a> <a name="beforebulkdestroy"></a>
## `beforeBulkDestroy(name, fn)` ## `beforeBulkDestroy(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L286) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L310)
A hook that is run before destroying instances in bulk A hook that is run before destroying instances in bulk
**Params:** **Params:**
...@@ -256,7 +286,7 @@ __Aliases:__ beforeBulkDelete ...@@ -256,7 +286,7 @@ __Aliases:__ beforeBulkDelete
<a name="afterbulkdestroy"></a> <a name="afterbulkdestroy"></a>
## `afterBulkDestroy(name, fn)` ## `afterBulkDestroy(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L295) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L319)
A hook that is run after destroying instances in bulk A hook that is run after destroying instances in bulk
**Params:** **Params:**
...@@ -270,9 +300,39 @@ __Aliases:__ afterBulkDelete ...@@ -270,9 +300,39 @@ __Aliases:__ afterBulkDelete
*** ***
<a name="beforebulkrestore"></a>
## `beforeBulkRestore(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L327)
A hook that is run before restoring instances in bulk
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| name | String | |
| fn | Function | A callback function that is called with options |
***
<a name="afterbulkrestore"></a>
## `afterBulkRestore(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L335)
A hook that is run after restoring instances in bulk
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| name | String | |
| fn | Function | A callback function that is called with options |
***
<a name="beforebulkupdate"></a> <a name="beforebulkupdate"></a>
## `beforeBulkUpdate(name, fn)` ## `beforeBulkUpdate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L302) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L342)
A hook that is run after updating instances in bulk A hook that is run after updating instances in bulk
**Params:** **Params:**
...@@ -287,7 +347,7 @@ A hook that is run after updating instances in bulk ...@@ -287,7 +347,7 @@ A hook that is run after updating instances in bulk
<a name="afterbulkupdate"></a> <a name="afterbulkupdate"></a>
## `afterBulkUpdate(name, fn)` ## `afterBulkUpdate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L309) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L349)
A hook that is run after updating instances in bulk A hook that is run after updating instances in bulk
**Params:** **Params:**
...@@ -302,7 +362,7 @@ A hook that is run after updating instances in bulk ...@@ -302,7 +362,7 @@ A hook that is run after updating instances in bulk
<a name="beforefind"></a> <a name="beforefind"></a>
## `beforeFind(name, fn)` ## `beforeFind(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L316) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L356)
A hook that is run before a find (select) query A hook that is run before a find (select) query
**Params:** **Params:**
...@@ -317,7 +377,7 @@ A hook that is run before a find (select) query ...@@ -317,7 +377,7 @@ A hook that is run before a find (select) query
<a name="beforefindafterexpandincludeall"></a> <a name="beforefindafterexpandincludeall"></a>
## `beforeFindAfterExpandIncludeAll(name, fn)` ## `beforeFindAfterExpandIncludeAll(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L323) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L363)
A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded
**Params:** **Params:**
...@@ -332,7 +392,7 @@ A hook that is run before a find (select) query, after any { include: {all: ...} ...@@ -332,7 +392,7 @@ A hook that is run before a find (select) query, after any { include: {all: ...}
<a name="beforefindafteroptions"></a> <a name="beforefindafteroptions"></a>
## `beforeFindAfterOptions(name, fn)` ## `beforeFindAfterOptions(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L330) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L370)
A hook that is run before a find (select) query, after all option parsing is complete A hook that is run before a find (select) query, after all option parsing is complete
**Params:** **Params:**
...@@ -347,7 +407,7 @@ A hook that is run before a find (select) query, after all option parsing is com ...@@ -347,7 +407,7 @@ A hook that is run before a find (select) query, after all option parsing is com
<a name="afterfind"></a> <a name="afterfind"></a>
## `afterFind(name, fn)` ## `afterFind(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L337) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L377)
A hook that is run after a find (select) query A hook that is run after a find (select) query
**Params:** **Params:**
...@@ -362,7 +422,7 @@ A hook that is run after a find (select) query ...@@ -362,7 +422,7 @@ A hook that is run after a find (select) query
<a name="beforedefine"></a> <a name="beforedefine"></a>
## `beforeDefine(name, fn)` ## `beforeDefine(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L344) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L384)
A hook that is run before a define call A hook that is run before a define call
**Params:** **Params:**
...@@ -377,7 +437,7 @@ A hook that is run before a define call ...@@ -377,7 +437,7 @@ A hook that is run before a define call
<a name="afterdefine"></a> <a name="afterdefine"></a>
## `afterDefine(name, fn)` ## `afterDefine(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L351) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L391)
A hook that is run after a define call A hook that is run after a define call
**Params:** **Params:**
...@@ -392,7 +452,7 @@ A hook that is run after a define call ...@@ -392,7 +452,7 @@ A hook that is run after a define call
<a name="beforeinit"></a> <a name="beforeinit"></a>
## `beforeInit(name, fn)` ## `beforeInit(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L358) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L398)
A hook that is run before Sequelize() call A hook that is run before Sequelize() call
**Params:** **Params:**
...@@ -406,8 +466,8 @@ A hook that is run before Sequelize() call ...@@ -406,8 +466,8 @@ A hook that is run before Sequelize() call
*** ***
<a name="afterinit"></a> <a name="afterinit"></a>
## `afterInit` ## `afterInit(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/hooks.js#L366) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L405)
A hook that is run after Sequelize() call A hook that is run after Sequelize() call
**Params:** **Params:**
...@@ -420,4 +480,64 @@ A hook that is run after Sequelize() call ...@@ -420,4 +480,64 @@ A hook that is run after Sequelize() call
*** ***
<a name="beforesync"></a>
## `beforeSync(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L412)
A hook that is run before Model.sync call
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| name | String | |
| fn | Function | A callback function that is called with options passed to Model.sync |
***
<a name="aftersync"></a>
## `afterSync(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L419)
A hook that is run after Model.sync call
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| name | String | |
| fn | Function | A callback function that is called with options passed to Model.sync |
***
<a name="beforebulksync"></a>
## `beforeBulkSync(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L426)
A hook that is run before sequelize.sync call
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| name | String | |
| fn | Function | A callback function that is called with options passed to sequelize.sync |
***
<a name="afterbulksync"></a>
## `afterBulkSync`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/hooks.js#L434)
A hook that is run after sequelize.sync call
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| name | String | |
| fn | Function | A callback function that is called with options passed to sequelize.sync |
***
_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 <a href="irc://irc.freenode.net/#sequelizejs">IRC</a>, 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](http://usejsdoc.org) and [dox](https://github.com/tj/dox)_ _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 <a href="irc://irc.freenode.net/#sequelizejs">IRC</a>, 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](http://usejsdoc.org) and [dox](https://github.com/tj/dox)_
\ No newline at end of file
<a name="instance"></a> <a name="instance"></a>
# Class Instance # Class Instance
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L85) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L85)
This class represents an single instance, a database row. You might see it referred to as both Instance and instance. You should not This class represents an single instance, a database row. You might see it referred to as both Instance and instance. You should not
instantiate the Instance class directly, instead you access it using the finder and creation methods on the model. instantiate the Instance class directly, instead you access it using the finder and creation methods on the model.
...@@ -26,14 +26,14 @@ Accessing properties directly or using `get` is preferred for regular use, `getD ...@@ -26,14 +26,14 @@ Accessing properties directly or using `get` is preferred for regular use, `getD
<a name="isnewrecord"></a> <a name="isnewrecord"></a>
## `isNewRecord` -> `Boolean` ## `isNewRecord` -> `Boolean`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L98) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L98)
Returns true if this instance has not yet been persisted to the database Returns true if this instance has not yet been persisted to the database
*** ***
<a name="model"></a> <a name="model"></a>
## `Model()` -> `Model` ## `Model()` -> `Model`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L107) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L107)
Returns the Model the instance was created from. Returns the Model the instance was created from.
**See:** **See:**
...@@ -45,7 +45,7 @@ Returns the Model the instance was created from. ...@@ -45,7 +45,7 @@ Returns the Model the instance was created from.
<a name="sequelize"></a> <a name="sequelize"></a>
## `sequelize()` -> `Sequelize` ## `sequelize()` -> `Sequelize`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L116) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L116)
A reference to the sequelize instance A reference to the sequelize instance
**See:** **See:**
...@@ -57,7 +57,7 @@ A reference to the sequelize instance ...@@ -57,7 +57,7 @@ A reference to the sequelize instance
<a name="where"></a> <a name="where"></a>
## `where()` -> `Object` ## `where()` -> `Object`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L126) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L126)
Get an object representing the query for this instance, use with `options.where` Get an object representing the query for this instance, use with `options.where`
...@@ -65,7 +65,7 @@ Get an object representing the query for this instance, use with `options.where` ...@@ -65,7 +65,7 @@ Get an object representing the query for this instance, use with `options.where`
<a name="getdatavalue"></a> <a name="getdatavalue"></a>
## `getDataValue(key)` -> `any` ## `getDataValue(key)` -> `any`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L150) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L150)
Get the value of the underlying data value Get the value of the underlying data value
...@@ -80,7 +80,7 @@ Get the value of the underlying data value ...@@ -80,7 +80,7 @@ Get the value of the underlying data value
<a name="setdatavalue"></a> <a name="setdatavalue"></a>
## `setDataValue(key, value)` ## `setDataValue(key, value)`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L160) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L160)
Update the underlying data value Update the underlying data value
...@@ -96,7 +96,7 @@ Update the underlying data value ...@@ -96,7 +96,7 @@ Update the underlying data value
<a name="get"></a> <a name="get"></a>
## `get([key], [options])` -> `Object|any` ## `get([key], [options])` -> `Object|any`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L179) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L179)
If no key is given, returns all values of the instance, also invoking virtual getters. If no key is given, returns all values of the instance, also invoking virtual getters.
If key is given and a field or virtual getter is present for the key it will call that getter - else it will return the value for key. If key is given and a field or virtual getter is present for the key it will call that getter - else it will return the value for key.
...@@ -115,7 +115,7 @@ If key is given and a field or virtual getter is present for the key it will cal ...@@ -115,7 +115,7 @@ If key is given and a field or virtual getter is present for the key it will cal
<a name="set"></a> <a name="set"></a>
## `set(key, value, [options])` ## `set(key, value, [options])`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L249) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L249)
Set is used to update values on the instance (the sequelize representation of the instance that is, remember that nothing will be persisted before you actually call `save`). Set is used to update values on the instance (the sequelize representation of the instance that is, remember that nothing will be persisted before you actually call `save`).
In its most basic form `set` will update a value stored in the underlying `dataValues` object. However, if a custom setter function is defined for the key, that function In its most basic form `set` will update a value stored in the underlying `dataValues` object. However, if a custom setter function is defined for the key, that function
will be called instead. To bypass the setter, you can pass `raw: true` in the options object. will be called instead. To bypass the setter, you can pass `raw: true` in the options object.
...@@ -153,7 +153,7 @@ __Aliases:__ setAttributes ...@@ -153,7 +153,7 @@ __Aliases:__ setAttributes
<a name="changed"></a> <a name="changed"></a>
## `changed([key])` -> `Boolean|Array` ## `changed([key])` -> `Boolean|Array`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L394) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L402)
If changed is called with a string it will return a boolean indicating whether the value of that key in `dataValues` is different from the value in `_previousDataValues`. If changed is called with a string it will return a boolean indicating whether the value of that key in `dataValues` is different from the value in `_previousDataValues`.
If changed is called without an argument, it will return an array of keys that have changed. If changed is called without an argument, it will return an array of keys that have changed.
...@@ -172,7 +172,7 @@ If changed is called without an argument and no keys have changed, it will retur ...@@ -172,7 +172,7 @@ If changed is called without an argument and no keys have changed, it will retur
<a name="previous"></a> <a name="previous"></a>
## `previous(key)` -> `any` ## `previous(key)` -> `any`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L415) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L423)
Returns the previous value for key from `_previousDataValues`. Returns the previous value for key from `_previousDataValues`.
**Params:** **Params:**
...@@ -186,8 +186,8 @@ Returns the previous value for key from `_previousDataValues`. ...@@ -186,8 +186,8 @@ Returns the previous value for key from `_previousDataValues`.
<a name="save"></a> <a name="save"></a>
## `save([options])` -> `Promise.<this|Errors.ValidationError>` ## `save([options])` -> `Promise.<this|Errors.ValidationError>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L476) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L485)
Validate this instance, and if the validation passes, persist it to the database. Validate this instance, and if the validation passes, persist it to the database. It will only save changed fields, and do nothing if no fields have changed.
On success, the callback will be called with this instance. On validation error, the callback will be called with an instance of `Sequelize.ValidationError`. On success, the callback will be called with this instance. On validation error, the callback will be called with an instance of `Sequelize.ValidationError`.
This error will have a property for each of the fields for which validation failed, with the error message for that field. This error will have a property for each of the fields for which validation failed, with the error message for that field.
...@@ -203,13 +203,14 @@ This error will have a property for each of the fields for which validation fail ...@@ -203,13 +203,14 @@ This error will have a property for each of the fields for which validation fail
| [options.validate=true] | Boolean | If false, validations won't be run. | | [options.validate=true] | Boolean | If false, validations won't be run. |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. | | [options.logging=false] | Function | A function that gets executed while running the query to log the sql. |
| [options.transaction] | Transaction | | | [options.transaction] | Transaction | |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
*** ***
<a name="reload"></a> <a name="reload"></a>
## `reload([options])` -> `Promise.<this>` ## `reload([options])` -> `Promise.<this>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L720) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L730)
Refresh the current instance in-place, i.e. update the object with current data from the DB and return the same object. Refresh the current instance in-place, i.e. update the object with current data from the DB and return the same object.
This is different from doing a `find(Instance.id)`, because that would create and return a new instance. With this method, This is different from doing a `find(Instance.id)`, because that would create and return a new instance. With this method,
all references to the Instance are updated with the new data and no new objects are created. all references to the Instance are updated with the new data and no new objects are created.
...@@ -232,7 +233,7 @@ all references to the Instance are updated with the new data and no new objects ...@@ -232,7 +233,7 @@ all references to the Instance are updated with the new data and no new objects
<a name="validate"></a> <a name="validate"></a>
## `validate([options])` -> `Promise.<Errors.ValidationError|undefined>` ## `validate([options])` -> `Promise.<Errors.ValidationError|undefined>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L746) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L756)
Validate the attribute of this instance according to validation rules set in the model definition. Validate the attribute of this instance according to validation rules set in the model definition.
Emits null if and only if validation successful; otherwise an Error instance containing { field name : [error msgs] } entries. Emits null if and only if validation successful; otherwise an Error instance containing { field name : [error msgs] } entries.
...@@ -255,7 +256,7 @@ Emits null if and only if validation successful; otherwise an Error instance con ...@@ -255,7 +256,7 @@ Emits null if and only if validation successful; otherwise an Error instance con
<a name="update"></a> <a name="update"></a>
## `update(updates, options)` -> `Promise.<this>` ## `update(updates, options)` -> `Promise.<this>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L765) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L775)
This is the same as calling `set` and then calling `save`. This is the same as calling `set` and then calling `save`.
...@@ -278,7 +279,7 @@ __Aliases:__ updateAttributes ...@@ -278,7 +279,7 @@ __Aliases:__ updateAttributes
<a name="destroy"></a> <a name="destroy"></a>
## `destroy([options={}])` -> `Promise.<undefined>` ## `destroy([options={}])` -> `Promise.<undefined>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L798) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L813)
Destroy the row corresponding to this instance. Depending on your setting for paranoid, the row will either be completely deleted, or have its deletedAt timestamp set to the current time. Destroy the row corresponding to this instance. Depending on your setting for paranoid, the row will either be completely deleted, or have its deletedAt timestamp set to the current time.
...@@ -290,13 +291,14 @@ Destroy the row corresponding to this instance. Depending on your setting for pa ...@@ -290,13 +291,14 @@ Destroy the row corresponding to this instance. Depending on your setting for pa
| [options.force=false] | Boolean | If set to true, paranoid models will actually be deleted | | [options.force=false] | Boolean | If set to true, paranoid models will actually be deleted |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. | | [options.logging=false] | Function | A function that gets executed while running the query to log the sql. |
| [options.transaction] | Transaction | | | [options.transaction] | Transaction | |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
*** ***
<a name="restore"></a> <a name="restore"></a>
## `restore([options={}])` -> `Promise.<undefined>` ## `restore([options={}])` -> `Promise.<undefined>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L842) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L857)
Restore the row corresponding to this instance. Only available for paranoid models. Restore the row corresponding to this instance. Only available for paranoid models.
...@@ -313,7 +315,7 @@ Restore the row corresponding to this instance. Only available for paranoid mode ...@@ -313,7 +315,7 @@ Restore the row corresponding to this instance. Only available for paranoid mode
<a name="increment"></a> <a name="increment"></a>
## `increment(fields, [options])` -> `Promise.<this>` ## `increment(fields, [options])` -> `Promise.<this>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L889) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L909)
Increment the value of one or more columns. This is done in the database, which means it does not use the values currently stored on the Instance. The increment is done using a Increment the value of one or more columns. This is done in the database, which means it does not use the values currently stored on the Instance. The increment is done using a
```sql ```sql
SET column = column + X SET column = column + X
...@@ -342,13 +344,14 @@ instance.increment({ answer: 42, tries: 1}, { by: 2 }) // increment answer by 42 ...@@ -342,13 +344,14 @@ instance.increment({ answer: 42, tries: 1}, { by: 2 }) // increment answer by 42
| [options.by=1] | Integer | The number to increment by | | [options.by=1] | Integer | The number to increment by |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. | | [options.logging=false] | Function | A function that gets executed while running the query to log the sql. |
| [options.transaction] | Transaction | | | [options.transaction] | Transaction | |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
*** ***
<a name="decrement"></a> <a name="decrement"></a>
## `decrement(fields, [options])` -> `Promise` ## `decrement(fields, [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L962) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L983)
Decrement the value of one or more columns. This is done in the database, which means it does not use the values currently stored on the Instance. The decrement is done using a Decrement the value of one or more columns. This is done in the database, which means it does not use the values currently stored on the Instance. The decrement is done using a
```sql ```sql
SET column = column - X SET column = column - X
...@@ -377,13 +380,14 @@ instance.decrement({ answer: 42, tries: 1}, { by: 2 }) // decrement answer by 42 ...@@ -377,13 +380,14 @@ instance.decrement({ answer: 42, tries: 1}, { by: 2 }) // decrement answer by 42
| [options.by=1] | Integer | The number to decrement by | | [options.by=1] | Integer | The number to decrement by |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. | | [options.logging=false] | Function | A function that gets executed while running the query to log the sql. |
| [options.transaction] | Transaction | | | [options.transaction] | Transaction | |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
*** ***
<a name="equals"></a> <a name="equals"></a>
## `equals(other)` -> `Boolean` ## `equals(other)` -> `Boolean`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L984) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L1005)
Check whether all values of this and `other` Instance are the same Check whether all values of this and `other` Instance are the same
...@@ -398,7 +402,7 @@ Check whether all values of this and `other` Instance are the same ...@@ -398,7 +402,7 @@ Check whether all values of this and `other` Instance are the same
<a name="equalsoneof"></a> <a name="equalsoneof"></a>
## `equalsOneOf(others)` -> `Boolean` ## `equalsOneOf(others)` -> `Boolean`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L1008) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L1029)
Check if this is eqaul to one of `others` by calling equals Check if this is eqaul to one of `others` by calling equals
...@@ -413,7 +417,7 @@ Check if this is eqaul to one of `others` by calling equals ...@@ -413,7 +417,7 @@ Check if this is eqaul to one of `others` by calling equals
<a name="tojson"></a> <a name="tojson"></a>
## `toJSON()` -> `object` ## `toJSON()` -> `object`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/instance.js#L1026) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/instance.js#L1047)
Convert the instance to a JSON representation. Proxies to calling `get` with no keys. This means get all values gotten from the DB, and apply all custom getters. Convert the instance to a JSON representation. Proxies to calling `get` with no keys. This means get all values gotten from the DB, and apply all custom getters.
......
<a name="model"></a> <a name="model"></a>
# Class Model # Class Model
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L23) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L26)
A Model represents a table in the database. Sometimes you might also see it referred to as model, or simply as factory. A Model represents a table in the database. Sometimes you might also see it referred to as model, or simply as factory.
This class should _not_ be instantiated directly, it is created using `sequelize.define`, and already created models can be loaded using `sequelize.import` This class should _not_ be instantiated directly, it is created using `sequelize.define`, and already created models can be loaded using `sequelize.import`
...@@ -12,7 +12,7 @@ This class should _not_ be instantiated directly, it is created using `sequelize ...@@ -12,7 +12,7 @@ This class should _not_ be instantiated directly, it is created using `sequelize
<a name="removeattribute"></a> <a name="removeattribute"></a>
## `removeAttribute([attribute])` ## `removeAttribute([attribute])`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L862) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L954)
Remove attribute from model definition Remove attribute from model definition
**Params:** **Params:**
...@@ -26,7 +26,7 @@ Remove attribute from model definition ...@@ -26,7 +26,7 @@ Remove attribute from model definition
<a name="sync"></a> <a name="sync"></a>
## `sync()` -> `Promise.<this>` ## `sync()` -> `Promise.<this>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L872) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L964)
Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model instance (this) Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model instance (this)
**See:** **See:**
...@@ -38,7 +38,7 @@ Sync this Model to the DB, that is create the table. Upon success, the callback ...@@ -38,7 +38,7 @@ Sync this Model to the DB, that is create the table. Upon success, the callback
<a name="drop"></a> <a name="drop"></a>
## `drop([options])` -> `Promise` ## `drop([options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L909) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1011)
Drop the table represented by this Model Drop the table represented by this Model
**Params:** **Params:**
...@@ -54,7 +54,7 @@ Drop the table represented by this Model ...@@ -54,7 +54,7 @@ Drop the table represented by this Model
<a name="schema"></a> <a name="schema"></a>
## `schema(schema, [options])` -> `this` ## `schema(schema, [options])` -> `this`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L927) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1029)
Apply a schema to this model. For postgres, this will actually place the schema in front of the table name - `"schema"."tableName"`, Apply a schema to this model. For postgres, this will actually place the schema in front of the table name - `"schema"."tableName"`,
while the schema will be prepended to the table name for mysql and sqlite - `'schema.tablename'`. while the schema will be prepended to the table name for mysql and sqlite - `'schema.tablename'`.
...@@ -73,7 +73,7 @@ while the schema will be prepended to the table name for mysql and sqlite - `'sc ...@@ -73,7 +73,7 @@ while the schema will be prepended to the table name for mysql and sqlite - `'sc
<a name="gettablename"></a> <a name="gettablename"></a>
## `getTableName([options])` -> `String|Object` ## `getTableName([options])` -> `String|Object`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L951) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1053)
Get the tablename of the model, taking schema into account. The method will return The name as a string if the model has no schema, Get the tablename of the model, taking schema into account. The method will return The name as a string if the model has no schema,
or an object with `tableName`, `schema` and `delimiter` properties. or an object with `tableName`, `schema` and `delimiter` properties.
...@@ -90,14 +90,34 @@ or an object with `tableName`, `schema` and `delimiter` properties. ...@@ -90,14 +90,34 @@ or an object with `tableName`, `schema` and `delimiter` properties.
<a name="unscoped"></a> <a name="unscoped"></a>
## `unscoped()` -> `Model` ## `unscoped()` -> `Model`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L958) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1060)
***
<a name="addscope"></a>
## `addScope(name, scope, [options])`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1074)
Add a new scope to the model. This is especially useful for adding scopes with includes, when the model you want to include is not available at the time this model is defined.
By default this will throw an error if a scope with that name already exists. Pass `override: true` in the options object to silence this error.
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| name | String | The name of the scope. Use `defaultScope` to override the default scope |
| scope | Object &#124; Function | |
| [options] | Object | |
| [options.override=false] | Boolean | |
*** ***
<a name="scope"></a> <a name="scope"></a>
## `scope(options*)` -> `Model` ## `scope(options*)` -> `Model`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1008) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1138)
Apply a scope created in `define` to the model. First let's look at how to create scopes: Apply a scope created in `define` to the model. First let's look at how to create scopes:
```js ```js
var Model = sequelize.define('model', attributes, { var Model = sequelize.define('model', attributes, {
...@@ -153,7 +173,7 @@ __Returns:__ A reference to the model, with the scope(s) applied. Calling scope ...@@ -153,7 +173,7 @@ __Returns:__ A reference to the model, with the scope(s) applied. Calling scope
<a name="findall"></a> <a name="findall"></a>
## `findAll([options])` -> `Promise.<Array.<Instance>>` ## `findAll([options])` -> `Promise.<Array.<Instance>>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1159) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1301)
Search for multiple instances. Search for multiple instances.
__Simple search using AND and =__ __Simple search using AND and =__
...@@ -197,17 +217,22 @@ Possible options are: `$ne, $in, $not, $notIn, $gte, $gt, $lte, $lt, $like, $ili ...@@ -197,17 +217,22 @@ Possible options are: `$ne, $in, $not, $notIn, $gte, $gt, $lte, $lt, $like, $ili
__Queries using OR__ __Queries using OR__
```js ```js
Model.findAll({ Model.findAll({
where: Sequelize.and( where: {
{ name: 'a project' }, name: 'a project',
Sequelize.or( $or: [
{ id: [1,2,3] }, {id: [1, 2, 3]},
{ id: { gt: 10 } } {
) $and: [
) {id: {gt: 10}},
}) {id: {lt: 100}}
]
}
]
}
});
``` ```
```sql ```sql
WHERE name = 'a project' AND (id` IN (1,2,3) OR id > 10) WHERE `Model`.`name` = 'a project' AND (`Model`.`id` IN (1, 2, 3) OR (`Model`.`id` > 10 AND `Model`.`id` < 100));
``` ```
The success listener is called with an array of instances if the query succeeds. The success listener is called with an array of instances if the query succeeds.
...@@ -233,6 +258,8 @@ The success listener is called with an array of instances if the query succeeds. ...@@ -233,6 +258,8 @@ The success listener is called with an array of instances if the query succeeds.
| [options.include[].where] | Object | Where clauses to apply to the child models. Note that this converts the eager load to an inner join, unless you explicitly set `required: false` | | [options.include[].where] | Object | Where clauses to apply to the child models. Note that this converts the eager load to an inner join, unless you explicitly set `required: false` |
| [options.include[].attributes] | Array.&lt;String&gt; | A list of attributes to select from the child model | | [options.include[].attributes] | Array.&lt;String&gt; | A list of attributes to select from the child model |
| [options.include[].required] | Boolean | If true, converts to an inner join, which means that the parent model will only be loaded if it has any matching children. True if `include.where` is set, false otherwise. | | [options.include[].required] | Boolean | If true, converts to an inner join, which means that the parent model will only be loaded if it has any matching children. True if `include.where` is set, false otherwise. |
| [options.include[].separate] | Boolean | If true, runs a separate query to fetch the associated instances, only supported for hasMany associations |
| [options.include[].limit] | Number | Limit the joined rows, only supported with include.separate=true |
| [options.include[].through.where] | Object | Filter on the join model for belongsToMany relations | | [options.include[].through.where] | Object | Filter on the join model for belongsToMany relations |
| [options.include[].through.attributes] | Array | A list of attributes to select from the join model for belongsToMany relations | | [options.include[].through.attributes] | Array | A list of attributes to select from the join model for belongsToMany relations |
| [options.include[].include] | Array.&lt;Object &#124; Model&gt; | Load further nested related models | | [options.include[].include] | Array.&lt;Object &#124; Model&gt; | Load further nested related models |
...@@ -244,6 +271,7 @@ The success listener is called with an array of instances if the query succeeds. ...@@ -244,6 +271,7 @@ The success listener is called with an array of instances if the query succeeds.
| [options.raw] | Boolean | Return raw result. See sequelize.query for more information. | | [options.raw] | Boolean | Return raw result. See sequelize.query for more information. |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. | | [options.logging=false] | Function | A function that gets executed while running the query to log the sql. |
| [options.having] | Object | | | [options.having] | Object | |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
__Aliases:__ all __Aliases:__ all
...@@ -251,7 +279,7 @@ __Aliases:__ all ...@@ -251,7 +279,7 @@ __Aliases:__ all
<a name="findbyid"></a> <a name="findbyid"></a>
## `findById([options], ')` -> `Promise.<Instance>` ## `findById([options], ')` -> `Promise.<Instance>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1238) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1432)
Search for a single instance by its primary key. This applies LIMIT 1, so the listener will always be called with a single instance. Search for a single instance by its primary key. This applies LIMIT 1, so the listener will always be called with a single instance.
...@@ -266,7 +294,8 @@ Search for a single instance by its primary key. This applies LIMIT 1, so the li ...@@ -266,7 +294,8 @@ Search for a single instance by its primary key. This applies LIMIT 1, so the li
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| [options] | Number &#124; String &#124; Buffer | A hash of options to describe the scope of the search, or a number to search by id. | | [options] | Number &#124; String &#124; Buffer | A hash of options to describe the scope of the search, or a number to search by id. |
| ' | Object | [options] | | ' | Object | [options] |
| [options.transaction] | Transaction | Transaction to run query under | | [options.transaction] | Transaction | Transaction to run query under |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
__Aliases:__ findByPrimary __Aliases:__ findByPrimary
...@@ -274,7 +303,7 @@ __Aliases:__ findByPrimary ...@@ -274,7 +303,7 @@ __Aliases:__ findByPrimary
<a name="findone"></a> <a name="findone"></a>
## `findOne([options])` -> `Promise.<Instance>` ## `findOne([options])` -> `Promise.<Instance>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1272) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1465)
Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single instance. Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single instance.
...@@ -288,7 +317,8 @@ Search for a single instance. This applies LIMIT 1, so the listener will always ...@@ -288,7 +317,8 @@ Search for a single instance. This applies LIMIT 1, so the listener will always
| Name | Type | Description | | Name | Type | Description |
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| [options] | Object | A hash of options to describe the scope of the search | | [options] | Object | A hash of options to describe the scope of the search |
| [options.transaction] | Transaction | Transaction to run query under | | [options.transaction] | Transaction | Transaction to run query under |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
__Aliases:__ find __Aliases:__ find
...@@ -296,7 +326,7 @@ __Aliases:__ find ...@@ -296,7 +326,7 @@ __Aliases:__ find
<a name="aggregate"></a> <a name="aggregate"></a>
## `aggregate(field, aggregateFunction, [options])` -> `Promise.<options.dataType|object>` ## `aggregate(field, aggregateFunction, [options])` -> `Promise.<options.dataType|object>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1304) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1497)
Run an aggregation method on the specified field Run an aggregation method on the specified field
...@@ -320,7 +350,7 @@ __Returns:__ Returns the aggregate result cast to `options.dataType`, unless `op ...@@ -320,7 +350,7 @@ __Returns:__ Returns the aggregate result cast to `options.dataType`, unless `op
<a name="count"></a> <a name="count"></a>
## `count([options])` -> `Promise.<Integer>` ## `count([options])` -> `Promise.<Integer>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1344) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1539)
Count the number of records matching the provided where clause. Count the number of records matching the provided where clause.
If you provide an `include` option, the number of matching associations will be counted instead. If you provide an `include` option, the number of matching associations will be counted instead.
...@@ -336,14 +366,16 @@ If you provide an `include` option, the number of matching associations will be ...@@ -336,14 +366,16 @@ If you provide an `include` option, the number of matching associations will be
| [options.distinct] | boolean | Apply COUNT(DISTINCT(col)) | | [options.distinct] | boolean | Apply COUNT(DISTINCT(col)) |
| [options.attributes] | Object | Used in conjustion with `group` | | [options.attributes] | Object | Used in conjustion with `group` |
| [options.group] | Object | For creating complex counts. Will return multiple rows as needed. | | [options.group] | Object | For creating complex counts. Will return multiple rows as needed. |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. | | [options.transaction] | Transaction | Transaction to run query under |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
*** ***
<a name="findandcount"></a> <a name="findandcount"></a>
## `findAndCount([findOptions])` -> `Promise.<Object>` ## `findAndCount([findOptions])` -> `Promise.<Object>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1402) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1597)
Find all the rows matching your query, within a specified offset / limit, and get the total number of rows matching your query. This is very usefull for paging Find all the rows matching your query, within a specified offset / limit, and get the total number of rows matching your query. This is very usefull for paging
```js ```js
...@@ -388,7 +420,7 @@ __Aliases:__ findAndCountAll ...@@ -388,7 +420,7 @@ __Aliases:__ findAndCountAll
<a name="max"></a> <a name="max"></a>
## `max(field, [options])` -> `Promise.<Any>` ## `max(field, [options])` -> `Promise.<Any>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1466) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1661)
Find the maximum value of field Find the maximum value of field
...@@ -409,7 +441,7 @@ Find the maximum value of field ...@@ -409,7 +441,7 @@ Find the maximum value of field
<a name="min"></a> <a name="min"></a>
## `min(field, [options])` -> `Promise.<Any>` ## `min(field, [options])` -> `Promise.<Any>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1479) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1674)
Find the minimum value of field Find the minimum value of field
...@@ -430,7 +462,7 @@ Find the minimum value of field ...@@ -430,7 +462,7 @@ Find the minimum value of field
<a name="sum"></a> <a name="sum"></a>
## `sum(field, [options])` -> `Promise.<Number>` ## `sum(field, [options])` -> `Promise.<Number>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1492) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1687)
Find the sum of field Find the sum of field
...@@ -451,7 +483,7 @@ Find the sum of field ...@@ -451,7 +483,7 @@ Find the sum of field
<a name="build"></a> <a name="build"></a>
## `build(values, [options])` -> `Instance` ## `build(values, [options])` -> `Instance`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1507) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1702)
Builds a new model instance. Values is an object of key value pairs, must be defined but can be empty. Builds a new model instance. Values is an object of key value pairs, must be defined but can be empty.
...@@ -470,7 +502,7 @@ Builds a new model instance. Values is an object of key value pairs, must be def ...@@ -470,7 +502,7 @@ Builds a new model instance. Values is an object of key value pairs, must be def
<a name="create"></a> <a name="create"></a>
## `create(values, [options])` -> `Promise.<Instance>` ## `create(values, [options])` -> `Promise.<Instance>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1575) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1771)
Builds a new model instance and calls save on it. Builds a new model instance and calls save on it.
...@@ -492,14 +524,15 @@ Builds a new model instance and calls save on it. ...@@ -492,14 +524,15 @@ Builds a new model instance and calls save on it.
| [options.include] | Array | an array of include options - Used to build prefetched/included model instances | | [options.include] | Array | an array of include options - Used to build prefetched/included model instances |
| [options.onDuplicate] | String | | | [options.onDuplicate] | String | |
| [options.transaction] | Transaction | Transaction to run query under | | [options.transaction] | Transaction | Transaction to run query under |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. | | [options.logging=false] | Function | A function that gets executed while running the query to log the sql. |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
*** ***
<a name="findorinitialize"></a> <a name="findorinitialize"></a>
## `findOrInitialize` -> `Promise.<Instance>` ## `findOrInitialize` -> `Promise.<Instance, initialized>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1600) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1796)
Find a row that matches the query, or build (but don't save) the row if none is found. Find a row that matches the query, or build (but don't save) the row if none is found.
The successfull result of the promise will be (instance, initialized) - Make sure to use .spread() The successfull result of the promise will be (instance, initialized) - Make sure to use .spread()
...@@ -520,7 +553,7 @@ __Aliases:__ findOrBuild ...@@ -520,7 +553,7 @@ __Aliases:__ findOrBuild
<a name="findorcreate"></a> <a name="findorcreate"></a>
## `findOrCreate(options)` -> `Promise.<Instance, created>` ## `findOrCreate(options)` -> `Promise.<Instance, created>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1642) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1838)
Find a row that matches the query, or build and save the row if none is found Find a row that matches the query, or build and save the row if none is found
The successfull result of the promise will be (instance, created) - Make sure to use .spread() The successfull result of the promise will be (instance, created) - Make sure to use .spread()
...@@ -546,9 +579,32 @@ If a transaction is created, a savepoint will be created instead, and any unique ...@@ -546,9 +579,32 @@ If a transaction is created, a savepoint will be created instead, and any unique
*** ***
<a name="findcreatefind"></a>
## `findCreateFind(options)` -> `Promise.<Instance, created>`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1924)
A more performant findOrCreate that will not work under a transaction (atleast not in postgres)
Will execute a find call, if empty then attempt to create, if unique constraint then attempt to find again
**See:**
* [Model#findAll](model#findall)
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| options | Object | |
| options.where | Object | where A hash of search attributes. |
| [options.defaults] | Object | Default values to use if creating a new instance |
***
<a name="upsert"></a> <a name="upsert"></a>
## `upsert(values, [options])` -> `Promise.<created>` ## `upsert(values, [options])` -> `Promise.<created>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1735) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L1972)
Insert or update a single row. An update will be executed if a row which matches the supplied values on either the primary key or a unique key is found. Note that the unique index must be defined in your sequelize model and not just in the table. Otherwise you may experience a unique constraint violation, because sequelize fails to identify the row that should be updated. Insert or update a single row. An update will be executed if a row which matches the supplied values on either the primary key or a unique key is found. Note that the unique index must be defined in your sequelize model and not just in the table. Otherwise you may experience a unique constraint violation, because sequelize fails to identify the row that should be updated.
**Implementation details:** **Implementation details:**
...@@ -568,7 +624,9 @@ Insert or update a single row. An update will be executed if a row which matches ...@@ -568,7 +624,9 @@ Insert or update a single row. An update will be executed if a row which matches
| [options] | Object | | | [options] | Object | |
| [options.validate=true] | Boolean | Run validations before the row is inserted | | [options.validate=true] | Boolean | Run validations before the row is inserted |
| [options.fields=Object.keys(this.attributes)] | Array | The fields to insert / update. Defaults to all fields | | [options.fields=Object.keys(this.attributes)] | Array | The fields to insert / update. Defaults to all fields |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. | | [options.transaction] | Transaction | Transaction to run query under |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
__Returns:__ Returns a boolean indicating whether the row was created or updated. __Returns:__ Returns a boolean indicating whether the row was created or updated.
__Aliases:__ insertOrUpdate __Aliases:__ insertOrUpdate
...@@ -577,7 +635,7 @@ __Aliases:__ insertOrUpdate ...@@ -577,7 +635,7 @@ __Aliases:__ insertOrUpdate
<a name="bulkcreate"></a> <a name="bulkcreate"></a>
## `bulkCreate(records, [options])` -> `Promise.<Array.<Instance>>` ## `bulkCreate(records, [options])` -> `Promise.<Array.<Instance>>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1795) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L2033)
Create and insert multiple instances in bulk. Create and insert multiple instances in bulk.
The success handler is passed an array of instances, but please notice that these may not completely represent the state of the rows in the DB. This is because MySQL The success handler is passed an array of instances, but please notice that these may not completely represent the state of the rows in the DB. This is because MySQL
...@@ -598,14 +656,15 @@ To obtain Instances for the newly created values, you will need to query for the ...@@ -598,14 +656,15 @@ To obtain Instances for the newly created values, you will need to query for the
| [options.ignoreDuplicates=false] | Boolean | Ignore duplicate values for primary keys? (not supported by postgres) | | [options.ignoreDuplicates=false] | Boolean | Ignore duplicate values for primary keys? (not supported by postgres) |
| [options.updateOnDuplicate] | Array | Fields to update if row key already exists (on duplicate key update)? (only supported by mysql & mariadb). By default, all fields are updated. | | [options.updateOnDuplicate] | Array | Fields to update if row key already exists (on duplicate key update)? (only supported by mysql & mariadb). By default, all fields are updated. |
| [options.transaction] | Transaction | Transaction to run query under | | [options.transaction] | Transaction | Transaction to run query under |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. | | [options.logging=false] | Function | A function that gets executed while running the query to log the sql. |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
*** ***
<a name="truncate"></a> <a name="truncate"></a>
## `truncate([options])` -> `Promise` ## `truncate([options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1943) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L2184)
Truncate all instances of the model. This is a convenient method for Model.destroy({ truncate: true }). Truncate all instances of the model. This is a convenient method for Model.destroy({ truncate: true }).
...@@ -621,14 +680,16 @@ Truncate all instances of the model. This is a convenient method for Model.destr ...@@ -621,14 +680,16 @@ Truncate all instances of the model. This is a convenient method for Model.destr
| [options] | object | The options passed to Model.destroy in addition to truncate | | [options] | object | The options passed to Model.destroy in addition to truncate |
| [options.transaction] | Boolean &#124; function | Transaction to run query under | | [options.transaction] | Boolean &#124; function | Transaction to run query under |
| [options.cascade | Boolean &#124; function | = false] Only used in conjuction with TRUNCATE. Truncates all tables that have foreign-key references to the named table, or to any tables added to the group due to CASCADE. | | [options.cascade | Boolean &#124; function | = false] Only used in conjuction with TRUNCATE. Truncates all tables that have foreign-key references to the named table, or to any tables added to the group due to CASCADE. |
| [options.transaction] | Transaction | Transaction to run query under |
| [options.logging] | Boolean &#124; function | A function that logs sql queries, or false for no logging | | [options.logging] | Boolean &#124; function | A function that logs sql queries, or false for no logging |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
*** ***
<a name="destroy"></a> <a name="destroy"></a>
## `destroy(options)` -> `Promise.<Integer>` ## `destroy(options)` -> `Promise.<Integer>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L1964) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L2205)
Delete multiple instances, or set their deletedAt timestamp to the current time if `paranoid` is enabled. Delete multiple instances, or set their deletedAt timestamp to the current time if `paranoid` is enabled.
...@@ -653,7 +714,7 @@ __Returns:__ The number of destroyed rows ...@@ -653,7 +714,7 @@ __Returns:__ The number of destroyed rows
<a name="restore"></a> <a name="restore"></a>
## `restore(options)` -> `Promise.<undefined>` ## `restore(options)` -> `Promise.<undefined>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L2041) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L2282)
Restore multiple instances if `paranoid` is enabled. Restore multiple instances if `paranoid` is enabled.
...@@ -674,7 +735,7 @@ Restore multiple instances if `paranoid` is enabled. ...@@ -674,7 +735,7 @@ Restore multiple instances if `paranoid` is enabled.
<a name="update"></a> <a name="update"></a>
## `update(values, options)` -> `Promise.<Array.<affectedCount, affectedRows>>` ## `update(values, options)` -> `Promise.<Array.<affectedCount, affectedRows>>`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L2114) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L2359)
Update multiple instances that match the where options. The promise returns an array with one or two elements. The first element is always the number Update multiple instances that match the where options. The promise returns an array with one or two elements. The first element is always the number
of affected rows, while the second element is the actual affected rows (only supported in postgres with `options.returning` true.) of affected rows, while the second element is the actual affected rows (only supported in postgres with `options.returning` true.)
...@@ -701,7 +762,7 @@ of affected rows, while the second element is the actual affected rows (only sup ...@@ -701,7 +762,7 @@ of affected rows, while the second element is the actual affected rows (only sup
<a name="describe"></a> <a name="describe"></a>
## `describe()` -> `Promise` ## `describe()` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/model.js#L2302) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/model.js#L2548)
Run a describe query on the table. The result will be return to the listener as a hash of attributes and their types. Run a describe query on the table. The result will be return to the listener as a hash of attributes and their types.
......
<a name="sequelize"></a> <a name="sequelize"></a>
# Class Sequelize # Class Sequelize
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L29) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L30)
This is the main class, the entry point to sequelize. To use it, you just need to import sequelize: This is the main class, the entry point to sequelize. To use it, you just need to import sequelize:
```js ```js
...@@ -14,7 +14,7 @@ In addition to sequelize, the connection library for the dialect you want to use ...@@ -14,7 +14,7 @@ In addition to sequelize, the connection library for the dialect you want to use
<a name="sequelize"></a> <a name="sequelize"></a>
## `new Sequelize(database, [username=null], [password=null], [options={}])` ## `new Sequelize(database, [username=null], [password=null], [options={}])`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L83) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L84)
Instantiate sequelize with name of database, username and password Instantiate sequelize with name of database, username and password
#### Example usage #### Example usage
...@@ -74,7 +74,7 @@ var sequelize = new Sequelize('mysql://localhost:3306/database', {}) ...@@ -74,7 +74,7 @@ var sequelize = new Sequelize('mysql://localhost:3306/database', {})
<a name="sequelize"></a> <a name="sequelize"></a>
## `new Sequelize(uri, [options={}])` ## `new Sequelize(uri, [options={}])`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L92) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L93)
Instantiate sequelize with an URI Instantiate sequelize with an URI
**Params:** **Params:**
...@@ -89,14 +89,21 @@ Instantiate sequelize with an URI ...@@ -89,14 +89,21 @@ Instantiate sequelize with an URI
<a name="models"></a> <a name="models"></a>
## `models` ## `models`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L189) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L210)
Models are stored here under the name given to `sequelize.define` Models are stored here under the name given to `sequelize.define`
*** ***
<a name="version"></a>
## `version`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L234)
Sequelize version number.
***
<a name="sequelize"></a> <a name="sequelize"></a>
## `Sequelize` ## `Sequelize`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L216) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L243)
A reference to Sequelize constructor from sequelize. Useful for accessing DataTypes, Errors etc. A reference to Sequelize constructor from sequelize. Useful for accessing DataTypes, Errors etc.
**See:** **See:**
...@@ -108,7 +115,7 @@ A reference to Sequelize constructor from sequelize. Useful for accessing DataTy ...@@ -108,7 +115,7 @@ A reference to Sequelize constructor from sequelize. Useful for accessing DataTy
<a name="utils"></a> <a name="utils"></a>
## `Utils` ## `Utils`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L223) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L250)
A reference to sequelize utilities. Most users will not need to use these utils directly. However, you might want to use `Sequelize.Utils._`, which is a reference to the lodash library, if you don't already have it imported in your project. A reference to sequelize utilities. Most users will not need to use these utils directly. However, you might want to use `Sequelize.Utils._`, which is a reference to the lodash library, if you don't already have it imported in your project.
**See:** **See:**
...@@ -120,26 +127,21 @@ A reference to sequelize utilities. Most users will not need to use these utils ...@@ -120,26 +127,21 @@ A reference to sequelize utilities. Most users will not need to use these utils
<a name="promise"></a> <a name="promise"></a>
## `Promise` ## `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L230) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L256)
A modified version of bluebird promises, that allows listening for sql events A handy reference to the bluebird Promise class
**See:**
* [Promise](promise)
*** ***
<a name="querytypes"></a> <a name="querytypes"></a>
## `QueryTypes` ## `QueryTypes`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L236) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L262)
Available query types for use with `sequelize.query` Available query types for use with `sequelize.query`
*** ***
<a name="validator"></a> <a name="validator"></a>
## `Validator` ## `Validator`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L243) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L269)
Exposes the validator.js object, so you can extend it with custom validation functions. The validator is exposed both on the instance, and on the constructor. Exposes the validator.js object, so you can extend it with custom validation functions. The validator is exposed both on the instance, and on the constructor.
**See:** **See:**
...@@ -151,7 +153,7 @@ Exposes the validator.js object, so you can extend it with custom validation fun ...@@ -151,7 +153,7 @@ Exposes the validator.js object, so you can extend it with custom validation fun
<a name="transaction"></a> <a name="transaction"></a>
## `Transaction` ## `Transaction`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L263) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L289)
A reference to the sequelize transaction class. Use this to access isolationLevels when creating a transaction A reference to the sequelize transaction class. Use this to access isolationLevels when creating a transaction
**See:** **See:**
...@@ -164,7 +166,7 @@ A reference to the sequelize transaction class. Use this to access isolationLeve ...@@ -164,7 +166,7 @@ A reference to the sequelize transaction class. Use this to access isolationLeve
<a name="deferrable"></a> <a name="deferrable"></a>
## `Deferrable` ## `Deferrable`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L271) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L297)
A reference to the deferrable collection. Use this to access the different deferrable options. A reference to the deferrable collection. Use this to access the different deferrable options.
**See:** **See:**
...@@ -177,7 +179,7 @@ A reference to the deferrable collection. Use this to access the different defer ...@@ -177,7 +179,7 @@ A reference to the deferrable collection. Use this to access the different defer
<a name="instance"></a> <a name="instance"></a>
## `Instance` ## `Instance`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L278) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L304)
A reference to the sequelize instance class. A reference to the sequelize instance class.
**See:** **See:**
...@@ -187,9 +189,21 @@ A reference to the sequelize instance class. ...@@ -187,9 +189,21 @@ A reference to the sequelize instance class.
*** ***
<a name="association"></a>
## `Association`
[View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L311)
A reference to the sequelize association class.
**See:**
* [Association](association)
***
<a name="error"></a> <a name="error"></a>
## `Error` ## `Error`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L291) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L324)
A general error class A general error class
**See:** **See:**
...@@ -201,7 +215,7 @@ A general error class ...@@ -201,7 +215,7 @@ A general error class
<a name="validationerror"></a> <a name="validationerror"></a>
## `ValidationError` ## `ValidationError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L299) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L332)
Emitted when a validation fails Emitted when a validation fails
**See:** **See:**
...@@ -213,7 +227,7 @@ Emitted when a validation fails ...@@ -213,7 +227,7 @@ Emitted when a validation fails
<a name="validationerroritem"></a> <a name="validationerroritem"></a>
## `ValidationErrorItem` ## `ValidationErrorItem`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L307) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L340)
Describes a validation error on an instance path Describes a validation error on an instance path
**See:** **See:**
...@@ -225,7 +239,7 @@ Describes a validation error on an instance path ...@@ -225,7 +239,7 @@ Describes a validation error on an instance path
<a name="databaseerror"></a> <a name="databaseerror"></a>
## `DatabaseError` ## `DatabaseError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L314) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L347)
A base class for all database related errors. A base class for all database related errors.
**See:** **See:**
...@@ -237,7 +251,7 @@ A base class for all database related errors. ...@@ -237,7 +251,7 @@ A base class for all database related errors.
<a name="timeouterror"></a> <a name="timeouterror"></a>
## `TimeoutError` ## `TimeoutError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L321) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L354)
Thrown when a database query times out because of a deadlock Thrown when a database query times out because of a deadlock
**See:** **See:**
...@@ -249,7 +263,7 @@ Thrown when a database query times out because of a deadlock ...@@ -249,7 +263,7 @@ Thrown when a database query times out because of a deadlock
<a name="uniqueconstrainterror"></a> <a name="uniqueconstrainterror"></a>
## `UniqueConstraintError` ## `UniqueConstraintError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L328) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L361)
Thrown when a unique constraint is violated in the database Thrown when a unique constraint is violated in the database
**See:** **See:**
...@@ -261,7 +275,7 @@ Thrown when a unique constraint is violated in the database ...@@ -261,7 +275,7 @@ Thrown when a unique constraint is violated in the database
<a name="exclusionconstrainterror"></a> <a name="exclusionconstrainterror"></a>
## `ExclusionConstraintError` ## `ExclusionConstraintError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L335) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L368)
Thrown when an exclusion constraint is violated in the database Thrown when an exclusion constraint is violated in the database
**See:** **See:**
...@@ -273,7 +287,7 @@ Thrown when an exclusion constraint is violated in the database ...@@ -273,7 +287,7 @@ Thrown when an exclusion constraint is violated in the database
<a name="foreignkeyconstrainterror"></a> <a name="foreignkeyconstrainterror"></a>
## `ForeignKeyConstraintError` ## `ForeignKeyConstraintError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L342) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L375)
Thrown when a foreign key constraint is violated in the database Thrown when a foreign key constraint is violated in the database
**See:** **See:**
...@@ -285,7 +299,7 @@ Thrown when a foreign key constraint is violated in the database ...@@ -285,7 +299,7 @@ Thrown when a foreign key constraint is violated in the database
<a name="connectionerror"></a> <a name="connectionerror"></a>
## `ConnectionError` ## `ConnectionError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L349) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L382)
A base class for all connection related errors. A base class for all connection related errors.
**See:** **See:**
...@@ -297,7 +311,7 @@ A base class for all connection related errors. ...@@ -297,7 +311,7 @@ A base class for all connection related errors.
<a name="connectionrefusederror"></a> <a name="connectionrefusederror"></a>
## `ConnectionRefusedError` ## `ConnectionRefusedError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L356) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L389)
Thrown when a connection to a database is refused Thrown when a connection to a database is refused
**See:** **See:**
...@@ -309,7 +323,7 @@ Thrown when a connection to a database is refused ...@@ -309,7 +323,7 @@ Thrown when a connection to a database is refused
<a name="accessdeniederror"></a> <a name="accessdeniederror"></a>
## `AccessDeniedError` ## `AccessDeniedError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L363) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L396)
Thrown when a connection to a database is refused due to insufficient access Thrown when a connection to a database is refused due to insufficient access
**See:** **See:**
...@@ -321,7 +335,7 @@ Thrown when a connection to a database is refused due to insufficient access ...@@ -321,7 +335,7 @@ Thrown when a connection to a database is refused due to insufficient access
<a name="hostnotfounderror"></a> <a name="hostnotfounderror"></a>
## `HostNotFoundError` ## `HostNotFoundError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L370) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L403)
Thrown when a connection to a database has a hostname that was not found Thrown when a connection to a database has a hostname that was not found
**See:** **See:**
...@@ -333,7 +347,7 @@ Thrown when a connection to a database has a hostname that was not found ...@@ -333,7 +347,7 @@ Thrown when a connection to a database has a hostname that was not found
<a name="hostnotreachableerror"></a> <a name="hostnotreachableerror"></a>
## `HostNotReachableError` ## `HostNotReachableError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L377) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L410)
Thrown when a connection to a database has a hostname that was not reachable Thrown when a connection to a database has a hostname that was not reachable
**See:** **See:**
...@@ -345,7 +359,7 @@ Thrown when a connection to a database has a hostname that was not reachable ...@@ -345,7 +359,7 @@ Thrown when a connection to a database has a hostname that was not reachable
<a name="invalidconnectionerror"></a> <a name="invalidconnectionerror"></a>
## `InvalidConnectionError` ## `InvalidConnectionError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L384) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L417)
Thrown when a connection to a database has invalid values for any of the connection parameters Thrown when a connection to a database has invalid values for any of the connection parameters
**See:** **See:**
...@@ -357,7 +371,7 @@ Thrown when a connection to a database has invalid values for any of the connect ...@@ -357,7 +371,7 @@ Thrown when a connection to a database has invalid values for any of the connect
<a name="connectiontimedouterror"></a> <a name="connectiontimedouterror"></a>
## `ConnectionTimedOutError` ## `ConnectionTimedOutError`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L391) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L424)
Thrown when a connection to a database times out Thrown when a connection to a database times out
**See:** **See:**
...@@ -369,7 +383,7 @@ Thrown when a connection to a database times out ...@@ -369,7 +383,7 @@ Thrown when a connection to a database times out
<a name="getdialect"></a> <a name="getdialect"></a>
## `getDialect()` -> `String` ## `getDialect()` -> `String`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L399) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L432)
Returns the specified dialect. Returns the specified dialect.
__Returns:__ The specified dialect. __Returns:__ The specified dialect.
...@@ -378,7 +392,7 @@ __Returns:__ The specified dialect. ...@@ -378,7 +392,7 @@ __Returns:__ The specified dialect.
<a name="getqueryinterface"></a> <a name="getqueryinterface"></a>
## `getQueryInterface()` -> `QueryInterface` ## `getQueryInterface()` -> `QueryInterface`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L411) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L444)
Returns an instance of QueryInterface. Returns an instance of QueryInterface.
...@@ -392,7 +406,7 @@ __Returns:__ An instance (singleton) of QueryInterface. ...@@ -392,7 +406,7 @@ __Returns:__ An instance (singleton) of QueryInterface.
<a name="define"></a> <a name="define"></a>
## `define(modelName, attributes, [options])` -> `Model` ## `define(modelName, attributes, [options])` -> `Model`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L514) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L547)
Define a new model, representing a table in the DB. Define a new model, representing a table in the DB.
The table columns are define by the hash that is given as the second argument. Each attribute of the hash represents a column. A short table definition might look like this: The table columns are define by the hash that is given as the second argument. Each attribute of the hash represents a column. A short table definition might look like this:
...@@ -501,7 +515,7 @@ For more about validation, see http://docs.sequelizejs.com/en/latest/docs/models ...@@ -501,7 +515,7 @@ For more about validation, see http://docs.sequelizejs.com/en/latest/docs/models
<a name="model"></a> <a name="model"></a>
## `model(modelName)` -> `Model` ## `model(modelName)` -> `Model`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L560) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L593)
Fetch a Model which is already defined Fetch a Model which is already defined
...@@ -516,7 +530,7 @@ Fetch a Model which is already defined ...@@ -516,7 +530,7 @@ Fetch a Model which is already defined
<a name="isdefined"></a> <a name="isdefined"></a>
## `isDefined(modelName)` -> `Boolean` ## `isDefined(modelName)` -> `Boolean`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L574) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L607)
Checks whether a model with the given name is defined Checks whether a model with the given name is defined
...@@ -531,7 +545,7 @@ Checks whether a model with the given name is defined ...@@ -531,7 +545,7 @@ Checks whether a model with the given name is defined
<a name="import"></a> <a name="import"></a>
## `import(path)` -> `Model` ## `import(path)` -> `Model`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L588) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L621)
Imports a model defined in another file Imports a model defined in another file
Imported models are cached, so multiple calls to import with the same path will not load the file multiple times Imported models are cached, so multiple calls to import with the same path will not load the file multiple times
...@@ -549,7 +563,7 @@ See https://github.com/sequelize/sequelize/blob/master/examples/using-multiple-m ...@@ -549,7 +563,7 @@ See https://github.com/sequelize/sequelize/blob/master/examples/using-multiple-m
<a name="query"></a> <a name="query"></a>
## `query(sql, [options={}])` -> `Promise` ## `query(sql, [options={}])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L641) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L678)
Execute a query on the DB, with the posibility to bypass all the sequelize goodness. Execute a query on the DB, with the posibility to bypass all the sequelize goodness.
By default, the function will return two arguments: an array of results, and a metadata object, containing number of affected rows etc. Use `.spread` to access the results. By default, the function will return two arguments: an array of results, and a metadata object, containing number of affected rows etc. Use `.spread` to access the results.
...@@ -587,14 +601,18 @@ sequelize.query('SELECT...', { type: sequelize.QueryTypes.SELECT }).then(functio ...@@ -587,14 +601,18 @@ sequelize.query('SELECT...', { type: sequelize.QueryTypes.SELECT }).then(functio
| [options.useMaster=false] | Boolean | Force the query to use the write pool, regardless of the query type. | | [options.useMaster=false] | Boolean | Force the query to use the write pool, regardless of the query type. |
| [options.logging=false] | Function | A function that gets executed while running the query to log the sql. | | [options.logging=false] | Function | A function that gets executed while running the query to log the sql. |
| [options.instance] | Instance | A sequelize instance used to build the return instance | | [options.instance] | Instance | A sequelize instance used to build the return instance |
| [options.model] | Model | A sequelize model used to build the returned model instances (used to be called callee) | | [options.model] | Model | A sequelize model used to build the returned model instances (used to be called callee) |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
| [options.supportsSearchPath] | Boolean | If false do not prepend the query with the search_path (Postgres only) |
| [options.mapToModel=false] | Object | Map returned fields to model's fields if `options.model` or `options.instance` is present. Mapping will occur before building the model instance. |
| [options.fieldMap] | Object | Map returned fields to arbitrary names for `SELECT` query type. |
*** ***
<a name="set"></a> <a name="set"></a>
## `set(variables, options)` -> `Promise` ## `set(variables, options)` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L735) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L789)
Execute a query which would set an environment or user variable. The variables are set per connection, so this function needs a transaction. Execute a query which would set an environment or user variable. The variables are set per connection, so this function needs a transaction.
Only works for MySQL. Only works for MySQL.
...@@ -612,7 +630,7 @@ Only works for MySQL. ...@@ -612,7 +630,7 @@ Only works for MySQL.
<a name="escape"></a> <a name="escape"></a>
## `escape(value)` -> `String` ## `escape(value)` -> `String`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L769) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L823)
Escape value. Escape value.
...@@ -627,7 +645,7 @@ Escape value. ...@@ -627,7 +645,7 @@ Escape value.
<a name="createschema"></a> <a name="createschema"></a>
## `createSchema(schema, options={})` -> `Promise` ## `createSchema(schema, options={})` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L785) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L839)
Create a new database schema. Create a new database schema.
Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
...@@ -652,7 +670,7 @@ not a database table. In mysql and sqlite, this command will do nothing. ...@@ -652,7 +670,7 @@ not a database table. In mysql and sqlite, this command will do nothing.
<a name="showallschemas"></a> <a name="showallschemas"></a>
## `showAllSchemas(options={})` -> `Promise` ## `showAllSchemas(options={})` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L798) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L852)
Show all defined schemas Show all defined schemas
Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
...@@ -670,7 +688,7 @@ not a database table. In mysql and sqlite, this will show all tables. ...@@ -670,7 +688,7 @@ not a database table. In mysql and sqlite, this will show all tables.
<a name="dropschema"></a> <a name="dropschema"></a>
## `dropSchema(schema, options={})` -> `Promise` ## `dropSchema(schema, options={})` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L812) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L866)
Drop a single schema Drop a single schema
Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
...@@ -689,7 +707,7 @@ not a database table. In mysql and sqlite, this drop a table matching the schema ...@@ -689,7 +707,7 @@ not a database table. In mysql and sqlite, this drop a table matching the schema
<a name="dropallschemas"></a> <a name="dropallschemas"></a>
## `dropAllSchemas(options={})` -> `Promise` ## `dropAllSchemas(options={})` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L825) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L879)
Drop all schemas Drop all schemas
Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
...@@ -707,7 +725,7 @@ not a database table. In mysql and sqlite, this is the equivalent of drop all ta ...@@ -707,7 +725,7 @@ not a database table. In mysql and sqlite, this is the equivalent of drop all ta
<a name="sync"></a> <a name="sync"></a>
## `sync([options={}])` -> `Promise` ## `sync([options={}])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L839) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L895)
Sync all defined models to the DB. Sync all defined models to the DB.
...@@ -720,13 +738,15 @@ Sync all defined models to the DB. ...@@ -720,13 +738,15 @@ Sync all defined models to the DB.
| [options.match] | RegEx | Match a regex against the database name before syncing, a safety check for cases where force: true is used in tests but not live code | | [options.match] | RegEx | Match a regex against the database name before syncing, a safety check for cases where force: true is used in tests but not live code |
| [options.logging=console.log] | Boolean &#124; function | A function that logs sql queries, or false for no logging | | [options.logging=console.log] | Boolean &#124; function | A function that logs sql queries, or false for no logging |
| [options.schema='public'] | String | The schema that the tables should be created in. This can be overriden for each table in sequelize.define | | [options.schema='public'] | String | The schema that the tables should be created in. This can be overriden for each table in sequelize.define |
| [options.searchPath=DEFAULT] | String | An optional parameter to specify the schema search_path (Postgres only) |
| [options.hooks=true] | Boolean | If hooks is true then beforeSync, afterSync, beforBulkSync, afterBulkSync hooks will be called |
*** ***
<a name="truncate"></a> <a name="truncate"></a>
## `truncate([options])` -> `Promise` ## `truncate([options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L888) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L951)
Truncate all tables defined through the sequelize models. This is done Truncate all tables defined through the sequelize models. This is done
by calling Model.truncate() on each model. by calling Model.truncate() on each model.
...@@ -749,7 +769,7 @@ by calling Model.truncate() on each model. ...@@ -749,7 +769,7 @@ by calling Model.truncate() on each model.
<a name="drop"></a> <a name="drop"></a>
## `drop(options)` -> `Promise` ## `drop(options)` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L910) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L973)
Drop all tables defined through this sequelize instance. This is done by calling Model.drop on each model Drop all tables defined through this sequelize instance. This is done by calling Model.drop on each model
**See:** **See:**
...@@ -769,7 +789,7 @@ Drop all tables defined through this sequelize instance. This is done by calling ...@@ -769,7 +789,7 @@ Drop all tables defined through this sequelize instance. This is done by calling
<a name="authenticate"></a> <a name="authenticate"></a>
## `authenticate()` -> `Promise` ## `authenticate()` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L932) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L995)
Test the connection by trying to authenticate Test the connection by trying to authenticate
__Aliases:__ validate __Aliases:__ validate
...@@ -778,7 +798,7 @@ __Aliases:__ validate ...@@ -778,7 +798,7 @@ __Aliases:__ validate
<a name="fn "></a> <a name="fn "></a>
## `fn (fn, args)` -> `Sequelize.fn` ## `fn (fn, args)` -> `Sequelize.fn`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L967) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L1028)
Creates a object representing a database function. This can be used in search queries, both in where and order parts, and as default values in column definitions. Creates a object representing a database function. This can be used in search queries, both in where and order parts, and as default values in column definitions.
If you want to refer to columns in your function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and not a strings. If you want to refer to columns in your function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and not a strings.
...@@ -810,7 +830,7 @@ instance.updateAttributes({ ...@@ -810,7 +830,7 @@ instance.updateAttributes({
<a name="col"></a> <a name="col"></a>
## `col(col)` -> `Sequelize.col` ## `col(col)` -> `Sequelize.col`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L980) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L1041)
Creates a object representing a column in the DB. This is often useful in conjunction with `sequelize.fn`, since raw string arguments to fn will be escaped. Creates a object representing a column in the DB. This is often useful in conjunction with `sequelize.fn`, since raw string arguments to fn will be escaped.
**See:** **See:**
...@@ -829,7 +849,7 @@ Creates a object representing a column in the DB. This is often useful in conjun ...@@ -829,7 +849,7 @@ Creates a object representing a column in the DB. This is often useful in conjun
<a name="cast"></a> <a name="cast"></a>
## `cast(val, type)` -> `Sequelize.cast` ## `cast(val, type)` -> `Sequelize.cast`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L994) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L1055)
Creates a object representing a call to the cast function. Creates a object representing a call to the cast function.
...@@ -845,7 +865,7 @@ Creates a object representing a call to the cast function. ...@@ -845,7 +865,7 @@ Creates a object representing a call to the cast function.
<a name="literal"></a> <a name="literal"></a>
## `literal(val)` -> `Sequelize.literal` ## `literal(val)` -> `Sequelize.literal`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L1007) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L1068)
Creates a object representing a literal, i.e. something that will not be escaped. Creates a object representing a literal, i.e. something that will not be escaped.
...@@ -861,7 +881,7 @@ __Aliases:__ asIs ...@@ -861,7 +881,7 @@ __Aliases:__ asIs
<a name="and"></a> <a name="and"></a>
## `and(args)` -> `Sequelize.and` ## `and(args)` -> `Sequelize.and`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L1020) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L1081)
An AND query An AND query
**See:** **See:**
...@@ -880,7 +900,7 @@ An AND query ...@@ -880,7 +900,7 @@ An AND query
<a name="or"></a> <a name="or"></a>
## `or(args)` -> `Sequelize.or` ## `or(args)` -> `Sequelize.or`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L1033) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L1094)
An OR query An OR query
**See:** **See:**
...@@ -899,7 +919,7 @@ An OR query ...@@ -899,7 +919,7 @@ An OR query
<a name="json"></a> <a name="json"></a>
## `json(conditions, [value])` -> `Sequelize.json` ## `json(conditions, [value])` -> `Sequelize.json`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L1046) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L1107)
Creates an object representing nested where conditions for postgres's json data-type. Creates an object representing nested where conditions for postgres's json data-type.
**See:** **See:**
...@@ -919,7 +939,7 @@ Creates an object representing nested where conditions for postgres's json data- ...@@ -919,7 +939,7 @@ Creates an object representing nested where conditions for postgres's json data-
<a name="where"></a> <a name="where"></a>
## `where(attr, [comparator='='], logic)` -> `Sequelize.where` ## `where(attr, [comparator='='], logic)` -> `Sequelize.where`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L1068) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L1129)
A way of specifying attr = condition. A way of specifying attr = condition.
The attr can either be an object taken from `Model.rawAttributes` (for example `Model.rawAttributes.id` or `Model.rawAttributes.name`). The The attr can either be an object taken from `Model.rawAttributes` (for example `Model.rawAttributes.id` or `Model.rawAttributes.name`). The
...@@ -939,7 +959,7 @@ For string attributes, use the regular `{ where: { attr: something }}` syntax. I ...@@ -939,7 +959,7 @@ For string attributes, use the regular `{ where: { attr: something }}` syntax. I
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| attr | Object | The attribute, which can be either an attribute object from `Model.rawAttributes` or a sequelize object, for example an instance of `sequelize.fn`. For simple string attributes, use the POJO syntax | | attr | Object | The attribute, which can be either an attribute object from `Model.rawAttributes` or a sequelize object, for example an instance of `sequelize.fn`. For simple string attributes, use the POJO syntax |
| [comparator='='] | string | | | [comparator='='] | string | |
| logic | String &#124; Object | The condition. Can be both a simply type, or a further condition (`.or`, `.and`, `.literal` etc.) | | logic | String &#124; Object | The condition. Can be both a simply type, or a further condition (`$or`, `$and`, `.literal` etc.) |
__Aliases:__ condition __Aliases:__ condition
...@@ -947,7 +967,7 @@ __Aliases:__ condition ...@@ -947,7 +967,7 @@ __Aliases:__ condition
<a name="transaction"></a> <a name="transaction"></a>
## `transaction([options={}])` -> `Promise` ## `transaction([options={}])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/sequelize.js#L1121) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/sequelize.js#L1182)
Start a transaction. When using transactions, you should pass the transaction in the options argument in order for the query to happen under that transaction Start a transaction. When using transactions, you should pass the transaction in the options argument in order for the query to happen under that transaction
```js ```js
......
<a name="transaction"></a> <a name="transaction"></a>
# Class Transaction # Class Transaction
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/transaction.js#L19) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/transaction.js#L19)
The transaction object is used to identify a running transaction. It is created by calling `Sequelize.transaction()`. The transaction object is used to identify a running transaction. It is created by calling `Sequelize.transaction()`.
To run a query under a transaction, you should pass the transaction in the options object. To run a query under a transaction, you should pass the transaction in the options object.
...@@ -20,7 +20,7 @@ To run a query under a transaction, you should pass the transaction in the optio ...@@ -20,7 +20,7 @@ To run a query under a transaction, you should pass the transaction in the optio
<a name="isolation_levels"></a> <a name="isolation_levels"></a>
## `ISOLATION_LEVELS` ## `ISOLATION_LEVELS`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/transaction.js#L71) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/transaction.js#L71)
Isolations levels can be set per-transaction by passing `options.isolationLevel` to `sequelize.transaction`. Isolations levels can be set per-transaction by passing `options.isolationLevel` to `sequelize.transaction`.
Default to `REPEATABLE_READ` but you can override the default isolation level by passing `options.isolationLevel` in `new Sequelize`. Default to `REPEATABLE_READ` but you can override the default isolation level by passing `options.isolationLevel` in `new Sequelize`.
...@@ -56,7 +56,7 @@ return sequelize.transaction({ ...@@ -56,7 +56,7 @@ return sequelize.transaction({
<a name="lock"></a> <a name="lock"></a>
## `LOCK` ## `LOCK`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/transaction.js#L115) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/transaction.js#L115)
Possible options for row locking. Used in conjuction with `find` calls: Possible options for row locking. Used in conjuction with `find` calls:
```js ```js
...@@ -95,16 +95,16 @@ UserModel will be locked but TaskModel won't! ...@@ -95,16 +95,16 @@ UserModel will be locked but TaskModel won't!
*** ***
<a name="commit"></a> <a name="commit"></a>
## `commit()` -> `this` ## `commit()` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/transaction.js#L127) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/transaction.js#L127)
Commit the transaction Commit the transaction
*** ***
<a name="rollback"></a> <a name="rollback"></a>
## `rollback()` -> `this` ## `rollback()` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/f678009d7514b81a6f87e12b86360e9a597e3ca8/lib/transaction.js#L148) [View code](https://github.com/sequelize/sequelize/blob/95f8fc2783814cd61ec1a8d623b23cd6a7cd5e17/lib/transaction.js#L154)
Rollback (abort) the transaction Rollback (abort) the transaction
......
...@@ -250,9 +250,8 @@ Sequelize.prototype.Sequelize = Sequelize; ...@@ -250,9 +250,8 @@ Sequelize.prototype.Sequelize = Sequelize;
Sequelize.prototype.Utils = Sequelize.Utils = Utils; Sequelize.prototype.Utils = Sequelize.Utils = Utils;
/** /**
* A modified version of bluebird promises, that allows listening for sql events * A handy reference to the bluebird Promise class
* @property Promise * @property Promise
* @see {Promise}
*/ */
Sequelize.prototype.Promise = Sequelize.Promise = Promise; Sequelize.prototype.Promise = Sequelize.Promise = Promise;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!