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

Commit 789c3dc9 by Jan Aagaard Meier

[ci skip] 📝 Add API docs for the methods added by associations

1 parent 861eef8f
<a name="belongstomany"></a>
# Mixin BelongsToMany
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to-many.js#L36)
Many-to-many association with a join table.
When the join table has additional attributes, these can be passed in the options object:
```js
UserProject = sequelize.define('user_project', {
role: Sequelize.STRING
});
User.belongsToMany(Project, { through: UserProject });
user.addProject(project, { role: 'manager', transaction: t });
```
All methods allow you to pass either a persisted instance, its primary key, or a mixture:
```js
Project.create({ id: 11 }).then(function (project) {
user.addProjects([project, 12]);
});
```
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()`.
***
<a name="getassociations"></a>
## `getAssociations([options])` -> `Promise.<Array.<Instance>>`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to-many.js#L200)
Get everything currently associated with this, using an optional where clause
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [options] | Object | |
| [options.where] | Object | An optional where clause to limit the associated models |
| [options.scope] | String &#124; Boolean | Apply a scope on the related model, or remove its default scope by passing false |
***
<a name="setassociations"></a>
## `setAssociations([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to-many.js#L210)
Set the associated models by passing an array of instances or their primary keys. Everything that it not in the passed array will be un-associated
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [newAssociations] | Array.&lt;Instance &#124; String &#124; Number&gt; | An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations. |
| [options] | Object | Options passed to `through.findAll`, `bulkCreate`, `update` and `destroy`. Can also hold additional attributes for the join table |
| [options.validate] | Object | Run validation for the join model |
***
<a name="addassociations"></a>
## `addAssociations([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to-many.js#L220)
Associate several instances with this
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [newAssociations] | Array.&lt;Instance &#124; String &#124; Number&gt; | An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations. |
| [options] | Object | Options passed to `through.findAll`, `bulkCreate`, and `update` `destroy`. Can also hold additional attributes for the join table |
| [options.validate] | Object | Run validation for the join model |
***
<a name="addassociation"></a>
## `addAssociation([newAssociation], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to-many.js#L230)
Associate several instances with this
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [newAssociation] | 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. |
| [options] | Object | Options passed to `through.findAll`, `bulkCreate` and `update`. Can also hold additional attributes for the join table |
| [options.validate] | Object | Run validation for the join model |
***
<a name="createassociation"></a>
## `createAssociation([values], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to-many.js#L239)
Create a new instance of the associated model and associate it with this.
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [values] | Object | |
| [options] | Object | Options passed to create and add. Can also hold additional attributes for the join table |
***
<a name="removeassociation"></a>
## `removeAssociation([oldAssociated], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to-many.js#L248)
Un-associate the instance
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [oldAssociated] | Instace &#124; String &#124; Number | Can be an Instance or its primary key |
| [options] | Object | Options passed to `through.destroy` |
***
<a name="removeassociations"></a>
## `removeAssociations([oldAssociated], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to-many.js#L257)
Un-associate several instances
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [oldAssociated] | Array.&lt;Instace &#124; String &#124; Number&gt; | Can be an Instance or its primary key |
| [options] | Object | Options passed to `through.destroy` |
***
<a name="hasassociation"></a>
## `hasAssociation([instance], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to-many.js#L266)
Check if an instance is associated with this.
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [instance] | Instace &#124; String &#124; Number | Can be an Instance or its primary key |
| [options] | Object | Options passed to getAssociations |
***
<a name="hasassociations"></a>
## `hasAssociations([instances], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to-many.js#L275)
Check if all instances are associated with this.
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [instances] | Array.&lt;Instace &#124; String &#124; Number&gt; | Can be an Instance or its primary key |
| [options] | Object | Options passed to getAssociations |
***
_This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on <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>
# Mixin BelongsTo
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to.js#L17)
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()`.
***
<a name="getassociation"></a>
## `getAssociation([options])` -> `Promise.<Instance>`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to.js#L81)
Get the associated instance
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [options] | Object | |
| [options.scope] | String &#124; Boolean | Apply a scope on the related model, or remove its default scope by passing false |
***
<a name="setassociation"></a>
## `setAssociation([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to.js#L91)
Set the associated model
**Params:**
| 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. |
| [options] | Object | Options passed to `this.save` |
| [options.save=true] | Boolean | Skip saving this after setting the foreign key if false. |
***
<a name="createassociation"></a>
## `createAssociation([values], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/belongs-to.js#L100)
Create a new instance of the associated model and associate it with this.
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [values] | Object | |
| [options] | Object | Options passed to `target.create` and setAssociation. |
***
_This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on <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="hasmany"></a>
# Mixin HasMany
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-many.js#L17)
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()`.
***
<a name="getassociations"></a>
## `getAssociations([options])` -> `Promise.<Array.<Instance>>`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-many.js#L84)
Get everything currently associated with this, using an optional where clause
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [options] | Object | |
| [options.where] | Object | An optional where clause to limit the associated models |
| [options.scope] | String &#124; Boolean | Apply a scope on the related model, or remove its default scope by passing false |
***
<a name="setassociations"></a>
## `setAssociations([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-many.js#L94)
Set the associated models by passing an array of instances or their primary keys. Everything that it not in the passed array will be un-associated
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [newAssociations] | Array.&lt;Instance &#124; String &#124; Number&gt; | An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations. |
| [options] | Object | Options passed to `target.findAll` and `update`. |
| [options.validate] | Object | Run validation for the join model |
***
<a name="addassociations"></a>
## `addAssociations([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-many.js#L104)
Associate several instances with this
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [newAssociations] | Array.&lt;Instance &#124; String &#124; Number&gt; | An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations. |
| [options] | Object | Options passed to `target.update`. |
| [options.validate] | Object | Run validation for the join model |
***
<a name="addassociation"></a>
## `addAssociation([newAssociation], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-many.js#L114)
Associate several instances with this
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [newAssociation] | 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. |
| [options] | Object | Options passed to `target.update`. |
| [options.validate] | Object | Run validation for the join model |
***
<a name="createassociation"></a>
## `createAssociation([values], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-many.js#L123)
Create a new instance of the associated model and associate it with this.
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [values] | Object | |
| [options] | Object | Options passed to `target.create`. |
***
<a name="removeassociation"></a>
## `removeAssociation([oldAssociated], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-many.js#L132)
Un-associate the instance
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [oldAssociated] | Instace &#124; String &#124; Number | Can be an Instance or its primary key |
| [options] | Object | Options passed to `target.update` |
***
<a name="removeassociations"></a>
## `removeAssociations([oldAssociated], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-many.js#L141)
Un-associate several instances
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [oldAssociated] | Array.&lt;Instace &#124; String &#124; Number&gt; | Can be an Instance or its primary key |
| [options] | Object | Options passed to `through.destroy` |
***
<a name="hasassociation"></a>
## `hasAssociation([instance], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-many.js#L150)
Check if an instance is associated with this.
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [instance] | Instace &#124; String &#124; Number | Can be an Instance or its primary key |
| [options] | Object | Options passed to getAssociations |
***
<a name="hasassociations"></a>
## `hasAssociations([instances], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-many.js#L159)
Check if all instances are associated with this.
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [instances] | Array.&lt;Instace &#124; String &#124; Number&gt; | Can be an Instance or its primary key |
| [options] | Object | Options passed to getAssociations |
***
_This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on <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>
# Mixin HasOne
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-one.js#L16)
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()`.
***
<a name="getassociation"></a>
## `getAssociation([options])` -> `Promise.<Instance>`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-one.js#L79)
Get the associated instance
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [options] | Object | |
| [options.scope] | String &#124; Boolean | Apply a scope on the related model, or remove its default scope by passing false |
***
<a name="setassociation"></a>
## `setAssociation([newAssociations], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-one.js#L88)
Set the associated model
**Params:**
| 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. |
| [options] | Object | Options passed to getAssocation and `target.save` |
***
<a name="createassociation"></a>
## `createAssociation([values], [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/associations/has-one.js#L97)
Create a new instance of the associated model and associate it with this.
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| [values] | Object | |
| [options] | Object | Options passed to `target.create` and setAssociation. |
***
_This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on <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="datatypes"></a> <a name="datatypes"></a>
# Class DataTypes # Class DataTypes
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L38) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L39)
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 definining a new model using `Sequelize.define`, like this:
```js ```js
sequelize.define('model', { sequelize.define('model', {
...@@ -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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L64) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L65)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L97) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L98)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L117) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L118)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L192) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L193)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L211) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L212)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L229) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L230)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L248) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L249)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L267) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L268)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L286) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L287)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L309) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L310)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L325) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L326)
A time column A time column
*** ***
<a name="date"></a> <a name="date"></a>
## `DATE()` ## `DATE()`
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L340) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L341)
A datetime column A datetime column
*** ***
<a name="dateonly"></a> <a name="dateonly"></a>
## `DATEONLY()` ## `DATEONLY()`
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L356) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L357)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L372) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L373)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L384) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L385)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L396) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L397)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L408) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L409)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L422) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L423)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L452) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L453)
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,28 +193,28 @@ See {@link http://www.postgresql.org/docs/9.4/static/rangetypes.html|Postgres do ...@@ -193,28 +193,28 @@ 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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L481) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L482)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L494) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L495)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L507) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L508)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L542) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L543)
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:
...@@ -244,7 +244,7 @@ __Aliases:__ NONE ...@@ -244,7 +244,7 @@ __Aliases:__ NONE
<a name="enum"></a> <a name="enum"></a>
## `ENUM()` ## `ENUM()`
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L555) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L556)
An enumeration. `DataTypes.ENUM('value', 'another value')`. An enumeration. `DataTypes.ENUM('value', 'another value')`.
...@@ -252,7 +252,7 @@ An enumeration. `DataTypes.ENUM('value', 'another value')`. ...@@ -252,7 +252,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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/data-types.js#L572) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/data-types.js#L573)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/deferrable.js#L39) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/deferrable.js#L59) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/deferrable.js#L76) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/deferrable.js#L95) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/deferrable.js#L114) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/deferrable.js#L135) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L11) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L20) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L41) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L49) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L70) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L84) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L92) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L98) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L104) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L109) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L114) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L119) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L127) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L138) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L157) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L177) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L201) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L213) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L220) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L230) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L241) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L252) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L263) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L274) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/errors.js#L285) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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="instance"></a> <a name="instance"></a>
# Class Instance # Class Instance
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L85) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L98) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L107) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L116) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L126) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L150) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L160) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L179) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L249) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L389) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L394)
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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L410) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L415)
Returns the previous value for key from `_previousDataValues`. Returns the previous value for key from `_previousDataValues`.
**Params:** **Params:**
...@@ -186,7 +186,7 @@ Returns the previous value for key from `_previousDataValues`. ...@@ -186,7 +186,7 @@ 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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L471) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L476)
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.
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`.
...@@ -209,7 +209,7 @@ This error will have a property for each of the fields for which validation fail ...@@ -209,7 +209,7 @@ This error will have a property for each of the fields for which validation fail
<a name="reload"></a> <a name="reload"></a>
## `reload([options])` -> `Promise.<this>` ## `reload([options])` -> `Promise.<this>`
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L715) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L720)
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 +232,7 @@ all references to the Instance are updated with the new data and no new objects ...@@ -232,7 +232,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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L744) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L746)
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 +255,7 @@ Emits null if and only if validation successful; otherwise an Error instance con ...@@ -255,7 +255,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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L763) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L765)
This is the same as calling `set` and then calling `save`. This is the same as calling `set` and then calling `save`.
...@@ -278,7 +278,7 @@ __Aliases:__ updateAttributes ...@@ -278,7 +278,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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L796) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L798)
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.
...@@ -296,7 +296,7 @@ Destroy the row corresponding to this instance. Depending on your setting for pa ...@@ -296,7 +296,7 @@ Destroy the row corresponding to this instance. Depending on your setting for pa
<a name="restore"></a> <a name="restore"></a>
## `restore([options={}])` -> `Promise.<undefined>` ## `restore([options={}])` -> `Promise.<undefined>`
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L840) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L842)
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 +313,7 @@ Restore the row corresponding to this instance. Only available for paranoid mode ...@@ -313,7 +313,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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L887) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L889)
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
...@@ -348,7 +348,7 @@ instance.increment({ answer: 42, tries: 1}, { by: 2 }) // increment answer by 42 ...@@ -348,7 +348,7 @@ instance.increment({ answer: 42, tries: 1}, { by: 2 }) // increment answer by 42
<a name="decrement"></a> <a name="decrement"></a>
## `decrement(fields, [options])` -> `Promise` ## `decrement(fields, [options])` -> `Promise`
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L960) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L962)
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
...@@ -383,7 +383,7 @@ instance.decrement({ answer: 42, tries: 1}, { by: 2 }) // decrement answer by 42 ...@@ -383,7 +383,7 @@ instance.decrement({ answer: 42, tries: 1}, { by: 2 }) // decrement answer by 42
<a name="equals"></a> <a name="equals"></a>
## `equals(other)` -> `Boolean` ## `equals(other)` -> `Boolean`
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L982) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L984)
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 +398,7 @@ Check whether all values of this and `other` Instance are the same ...@@ -398,7 +398,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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L1006) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L1008)
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 +413,7 @@ Check if this is eqaul to one of `others` by calling equals ...@@ -413,7 +413,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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/instance.js#L1024) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/instance.js#L1026)
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="transaction"></a> <a name="transaction"></a>
# Class Transaction # Class Transaction
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/transaction.js#L19) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/transaction.js#L71) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/transaction.js#L115) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/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
...@@ -96,7 +96,7 @@ UserModel will be locked but TaskModel won't! ...@@ -96,7 +96,7 @@ UserModel will be locked but TaskModel won't!
<a name="commit"></a> <a name="commit"></a>
## `commit()` -> `this` ## `commit()` -> `this`
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/transaction.js#L127) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/transaction.js#L127)
Commit the transaction Commit the transaction
...@@ -104,7 +104,7 @@ Commit the transaction ...@@ -104,7 +104,7 @@ Commit the transaction
<a name="rollback"></a> <a name="rollback"></a>
## `rollback()` -> `this` ## `rollback()` -> `this`
[View code](https://github.com/sequelize/sequelize/blob/2c4a9f3cf9887fb33c31e397e758dd4aa3374d01/lib/transaction.js#L148) [View code](https://github.com/sequelize/sequelize/blob/e1de2e37b2301ec55af21f17cf0ac3dbf5d60179/lib/transaction.js#L148)
Rollback (abort) the transaction Rollback (abort) the transaction
......
"use strict"; 'use strict';
var dox = require('dox') var dox = require('dox')
, program = require('commander') , program = require('commander')
...@@ -24,10 +24,14 @@ if (program.file) { ...@@ -24,10 +24,14 @@ if (program.file) {
{file:'lib/instance.js', output: 'instance'}, {file:'lib/instance.js', output: 'instance'},
{file:'lib/model.js', output: 'model'}, {file:'lib/model.js', output: 'model'},
{file:'lib/hooks.js', output: 'hooks'}, {file:'lib/hooks.js', output: 'hooks'},
{file:'lib/associations/mixin.js', output: 'associations'}, {file:'lib/associations/mixin.js', output: 'associations/index'},
{file:'lib/transaction.js', output: 'transaction'}, {file:'lib/transaction.js', output: 'transaction'},
{file:'lib/data-types.js', output: 'datatypes'}, {file:'lib/data-types.js', output: 'datatypes'},
{file:'lib/deferrable.js', output: 'deferrable'} {file:'lib/deferrable.js', output: 'deferrable'},
{file:'lib/associations/belongs-to-many.js', output: 'associations/belongs-to-many'},
{file:'lib/associations/has-many.js', output: 'associations/has-many'},
{file:'lib/associations/has-one.js', output: 'associations/has-one'},
{file:'lib/associations/belongs-to.js', output: 'associations/belongs-to'}
]; ];
} }
......
...@@ -7,6 +7,32 @@ var Utils = require('./../utils') ...@@ -7,6 +7,32 @@ var Utils = require('./../utils')
, CounterCache = require('../plugins/counter-cache') , CounterCache = require('../plugins/counter-cache')
, util = require('util'); , util = require('util');
/**
* Many-to-many association with a join table.
*
* When the join table has additional attributes, these can be passed in the options object:
*
* ```js
* UserProject = sequelize.define('user_project', {
* role: Sequelize.STRING
* });
* User.belongsToMany(Project, { through: UserProject });
*
* user.addProject(project, { role: 'manager', transaction: t });
* ```
*
* All methods allow you to pass either a persisted instance, its primary key, or a mixture:
*
* ```js
* Project.create({ id: 11 }).then(function (project) {
* user.addProjects([project, 12]);
* });
* ```
*
* 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()`.
*
* @mixin BelongsToMany
*/
var BelongsToMany = function(source, target, options) { var BelongsToMany = function(source, target, options) {
Association.call(this); Association.call(this);
...@@ -162,14 +188,90 @@ var BelongsToMany = function(source, target, options) { ...@@ -162,14 +188,90 @@ var BelongsToMany = function(source, target, options) {
, singular = Utils.uppercaseFirst(this.options.name.singular); , singular = Utils.uppercaseFirst(this.options.name.singular);
this.accessors = { this.accessors = {
/**
* Get everything currently associated with this, using an optional where clause
*
* @param {Object} [options]
* @param {Object} [options.where] An optional where clause to limit the associated models
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @return {Promise<Array<Instance>>}
* @method getAssociations
*/
get: 'get' + plural, get: 'get' + plural,
/**
* 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
*
* @param {Array<Instance|String|Number>} [newAssociations] An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Object} [options] Options passed to `through.findAll`, `bulkCreate`, `update` and `destroy`. Can also hold additional attributes for the join table
* @param {Object} [options.validate] Run validation for the join model
* @return {Promise}
* @method setAssociations
*/
set: 'set' + plural, set: 'set' + plural,
/**
* Associate several instances with this
*
* @param {Array<Instance|String|Number>} [newAssociations] An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Object} [options] Options passed to `through.findAll`, `bulkCreate`, and `update` `destroy`. Can also hold additional attributes for the join table
* @param {Object} [options.validate] Run validation for the join model
* @return {Promise}
* @method addAssociations
*/
addMultiple: 'add' + plural, addMultiple: 'add' + plural,
/**
* Associate several instances with this
*
* @param {Instance|String|Number} [newAssociation] An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Object} [options] Options passed to `through.findAll`, `bulkCreate` and `update`. Can also hold additional attributes for the join table
* @param {Object} [options.validate] Run validation for the join model
* @return {Promise}
* @method addAssociation
*/
add: 'add' + singular, add: 'add' + singular,
/**
* Create a new instance of the associated model and associate it with this.
*
* @param {Object} [values]
* @param {Object} [options] Options passed to create and add. Can also hold additional attributes for the join table
* @return {Promise}
* @method createAssociation
*/
create: 'create' + singular, create: 'create' + singular,
/**
* Un-associate the instance
*
* @param {Instace|String|Number} [oldAssociated] Can be an Instance or its primary key
* @param {Object} [options] Options passed to `through.destroy`
* @return {Promise}
* @method removeAssociation
*/
remove: 'remove' + singular, remove: 'remove' + singular,
/**
* Un-associate several instances
*
* @param {Array<Instace|String|Number>} [oldAssociated] Can be an Instance or its primary key
* @param {Object} [options] Options passed to `through.destroy`
* @return {Promise}
* @method removeAssociations
*/
removeMultiple: 'remove' + plural, removeMultiple: 'remove' + plural,
/**
* Check if an instance is associated with this.
*
* @param {Instace|String|Number} [instance] Can be an Instance or its primary key
* @param {Object} [options] Options passed to getAssociations
* @return {Promise}
* @method hasAssociation
*/
hasSingle: 'has' + singular, hasSingle: 'has' + singular,
/**
* Check if all instances are associated with this.
*
* @param {Array<Instace|String|Number>} [instances] Can be an Instance or its primary key
* @param {Object} [options] Options passed to getAssociations
* @return {Promise}
* @method hasAssociations
*/
hasAll: 'has' + plural hasAll: 'has' + plural
}; };
......
...@@ -7,6 +7,13 @@ var Utils = require('./../utils') ...@@ -7,6 +7,13 @@ var Utils = require('./../utils')
, Association = require('./base') , Association = require('./base')
, util = require('util'); , util = require('util');
/**
* 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()`.
*
* @mixin BelongsTo
*/
var BelongsTo = function(source, target, options) { var BelongsTo = function(source, target, options) {
Association.call(this); Association.call(this);
...@@ -63,8 +70,33 @@ var BelongsTo = function(source, target, options) { ...@@ -63,8 +70,33 @@ var BelongsTo = function(source, target, options) {
var singular = Utils.uppercaseFirst(this.options.name.singular); var singular = Utils.uppercaseFirst(this.options.name.singular);
this.accessors = { this.accessors = {
/**
* Get the associated instance
*
* @param {Object} [options]
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @return {Promise<Instance>}
* @method getAssociation
*/
get: 'get' + singular, get: 'get' + singular,
/**
* Set the associated model
*
* @param {Instance|String|Number} [newAssociations] An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Object} [options] Options passed to `this.save`
* @param {Boolean} [options.save=true] Skip saving this after setting the foreign key if false.
* @return {Promise}
* @method setAssociation
*/
set: 'set' + singular, set: 'set' + singular,
/**
* Create a new instance of the associated model and associate it with this.
*
* @param {Object} [values]
* @param {Object} [options] Options passed to `target.create` and setAssociation.
* @return {Promise}
* @method createAssociation
*/
create: 'create' + singular create: 'create' + singular
}; };
}; };
......
...@@ -7,6 +7,13 @@ var Utils = require('./../utils') ...@@ -7,6 +7,13 @@ var Utils = require('./../utils')
, CounterCache = require('../plugins/counter-cache') , CounterCache = require('../plugins/counter-cache')
, util = require('util'); , util = require('util');
/**
* 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()`.
*
* @mixin HasMany
*/
var HasMany = function(source, target, options) { var HasMany = function(source, target, options) {
Association.call(this); Association.call(this);
...@@ -65,14 +72,90 @@ var HasMany = function(source, target, options) { ...@@ -65,14 +72,90 @@ var HasMany = function(source, target, options) {
, singular = Utils.uppercaseFirst(this.options.name.singular); , singular = Utils.uppercaseFirst(this.options.name.singular);
this.accessors = { this.accessors = {
/**
* Get everything currently associated with this, using an optional where clause
*
* @param {Object} [options]
* @param {Object} [options.where] An optional where clause to limit the associated models
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @return {Promise<Array<Instance>>}
* @method getAssociations
*/
get: 'get' + plural, get: 'get' + plural,
/**
* 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
*
* @param {Array<Instance|String|Number>} [newAssociations] An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Object} [options] Options passed to `target.findAll` and `update`.
* @param {Object} [options.validate] Run validation for the join model
* @return {Promise}
* @method setAssociations
*/
set: 'set' + plural, set: 'set' + plural,
/**
* Associate several instances with this
*
* @param {Array<Instance|String|Number>} [newAssociations] An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Object} [options] Options passed to `target.update`.
* @param {Object} [options.validate] Run validation for the join model
* @return {Promise}
* @method addAssociations
*/
addMultiple: 'add' + plural, addMultiple: 'add' + plural,
/**
* Associate several instances with this
*
* @param {Instance|String|Number} [newAssociation] An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Object} [options] Options passed to `target.update`.
* @param {Object} [options.validate] Run validation for the join model
* @return {Promise}
* @method addAssociation
*/
add: 'add' + singular, add: 'add' + singular,
/**
* Create a new instance of the associated model and associate it with this.
*
* @param {Object} [values]
* @param {Object} [options] Options passed to `target.create`.
* @return {Promise}
* @method createAssociation
*/
create: 'create' + singular, create: 'create' + singular,
/**
* Un-associate the instance
*
* @param {Instace|String|Number} [oldAssociated] Can be an Instance or its primary key
* @param {Object} [options] Options passed to `target.update`
* @return {Promise}
* @method removeAssociation
*/
remove: 'remove' + singular, remove: 'remove' + singular,
/**
* Un-associate several instances
*
* @param {Array<Instace|String|Number>} [oldAssociated] Can be an Instance or its primary key
* @param {Object} [options] Options passed to `through.destroy`
* @return {Promise}
* @method removeAssociations
*/
removeMultiple: 'remove' + plural, removeMultiple: 'remove' + plural,
/**
* Check if an instance is associated with this.
*
* @param {Instace|String|Number} [instance] Can be an Instance or its primary key
* @param {Object} [options] Options passed to getAssociations
* @return {Promise}
* @method hasAssociation
*/
hasSingle: 'has' + singular, hasSingle: 'has' + singular,
/**
* Check if all instances are associated with this.
*
* @param {Array<Instace|String|Number>} [instances] Can be an Instance or its primary key
* @param {Object} [options] Options passed to getAssociations
* @return {Promise}
* @method hasAssociations
*/
hasAll: 'has' + plural hasAll: 'has' + plural
}; };
......
...@@ -6,6 +6,13 @@ var Utils = require('./../utils') ...@@ -6,6 +6,13 @@ var Utils = require('./../utils')
, Association = require('./base') , Association = require('./base')
, util = require('util'); , util = require('util');
/**
* 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()`.
*
* @mixin HasOne
*/
var HasOne = function(srcModel, targetModel, options) { var HasOne = function(srcModel, targetModel, options) {
Association.call(this); Association.call(this);
...@@ -61,8 +68,32 @@ var HasOne = function(srcModel, targetModel, options) { ...@@ -61,8 +68,32 @@ var HasOne = function(srcModel, targetModel, options) {
var singular = Utils.uppercaseFirst(this.options.name.singular); var singular = Utils.uppercaseFirst(this.options.name.singular);
this.accessors = { this.accessors = {
/**
* Get the associated instance
*
* @param {Object} [options]
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @return {Promise<Instance>}
* @method getAssociation
*/
get: 'get' + singular, get: 'get' + singular,
/**
* Set the associated model
*
* @param {Instance|String|Number} [newAssociations] An array of instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Object} [options] Options passed to getAssocation and `target.save`
* @return {Promise}
* @method setAssociation
*/
set: 'set' + singular, set: 'set' + singular,
/**
* Create a new instance of the associated model and associate it with this.
*
* @param {Object} [values]
* @param {Object} [options] Options passed to `target.create` and setAssociation.
* @return {Promise}
* @method createAssociation
*/
create: 'create' + singular create: 'create' + singular
}; };
}; };
......
...@@ -8,8 +8,7 @@ var Utils = require('./../utils') ...@@ -8,8 +8,7 @@ var Utils = require('./../utils')
, BelongsTo = require('./belongs-to'); , BelongsTo = require('./belongs-to');
/** /**
* Creating assocations in sequelize is done by calling one of the belongsTo / hasOne / hasMany functions * 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).
* 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
* * belongsTo - add a foreign key to source * * belongsTo - add a foreign key to source
...@@ -17,11 +16,9 @@ var Utils = require('./../utils') ...@@ -17,11 +16,9 @@ var Utils = require('./../utils')
* *
* Creating an association will add a foreign key constraint to the attributes. All associations use `CASCADE` on update and `SET NULL` on delete, except for n:m, which also uses `CASCADE` on delete. * Creating an association will add a foreign key constraint to the attributes. All associations use `CASCADE` on update and `SET NULL` on delete, except for n:m, which also uses `CASCADE` on delete.
* *
* When creating associations, you can provide an alias, via the `as` option. This is useful if the same model * When creating associations, you can provide an alias, via the `as` option. This is useful if the same model is associated twice, or you want your association to be called something other than the name of the target model.
* is associated twice, or you want your association to be called something other than the name of the target model. *
* As an example, consider the case where users have many pictures, one of which is their profile picture. All pictures * As an example, consider the case where users have many pictures, one of which is their profile picture. All pictures have a `userId`, but in addition the user model also has a `profilePictureId`, to be able to easily load the user's profile picture.
* have a `userId`, but in addition the user model also has a `profilePictureId`, to be able to easily load the user's profile
* picture.
* *
* ```js * ```js
* User.hasMany(Picture) * User.hasMany(Picture)
...@@ -50,14 +47,13 @@ var Utils = require('./../utils') ...@@ -50,14 +47,13 @@ var Utils = require('./../utils')
* ```js * ```js
* User.hasMany(Picture, { * User.hasMany(Picture, {
* foreignKey: { * foreignKey: {
* name: 'uid' * name: 'uid',
* allowNull: false * allowNull: false
* } * }
* }) * })
* ``` * ```
* *
* This specifies that the `uid` column can not be null. In most cases this will already be covered by the foreign key costraints, which sequelize creates automatically, * This specifies that the `uid` column can not be null. In most cases this will already be covered by the foreign key costraints, which sequelize creates automatically, but can be useful in case where the foreign keys are disabled, e.g. due to circular references (see `constraints: false` below).
* but can be usefull in case where the foreign keys are disabled, e.g. due to circular references (see `constraints: false` below).
* *
* When fetching associated models, you can limit your query to only load some models. These queries are written in the same way as queries to `find`/`findAll`. To only get pictures in JPG, you can do: * When fetching associated models, you can limit your query to only load some models. These queries are written in the same way as queries to `find`/`findAll`. To only get pictures in JPG, you can do:
* *
...@@ -82,14 +78,9 @@ var Utils = require('./../utils') ...@@ -82,14 +78,9 @@ var Utils = require('./../utils')
* user.addPicture(req.query.pid) // Here pid is just an integer, representing the primary key of the picture * user.addPicture(req.query.pid) // Here pid is just an integer, representing the primary key of the picture
* ``` * ```
* *
* In the example above we have specified that a user belongs to his profile picture. Conceptually, this might not make sense, * In the example above we have specified that a user belongs to his profile picture. Conceptually, this might not make sense, but since we want to add the foreign key to the user model this is the way to do it.
* but since we want to add the foreign key to the user model this is the way to do it. *
* Note how we also specified `constraints: false` for profile picture. This is because we add a foreign key from * Note how we also specified `constraints: false` for profile picture. This is because we add a foreign key from user to picture (profilePictureId), and from picture to user (userId). If we were to add foreign keys to both, it would create a cyclic dependency, and sequelize would not know which table to create first, since user depends on picture, and picture depends on user. These kinds of problems are detected by sequelize before the models are synced to the database, and you will get an error along the lines of `Error: Cyclic dependency found. 'users' is dependent of itself`. If you encounter this, you should either disable some constraints, or rethink your associations completely.
* user to picture (profilePictureId), and from picture to user (userId). If we were to add foreign keys to both, it would
* create a cyclic dependency, and sequelize would not know which table to create first, since user depends on picture, and picture
* depends on user. These kinds of problems are detected by sequelize before the models are synced to the database, and you will
* get an error along the lines of `Error: Cyclic dependency found. 'users' is dependent of itself`. If you encounter this,
* you should either disable some constraints, or rethink your associations completely.
* *
* @mixin Associations * @mixin Associations
*/ */
...@@ -125,14 +116,6 @@ var singleLinked = function (Type) { ...@@ -125,14 +116,6 @@ var singleLinked = function (Type) {
* *
* Example: `User.hasOne(Profile)`. This will add userId to the profile table. * Example: `User.hasOne(Profile)`. This will add userId to the profile table.
* *
* The following methods are injected on the source:
*
* * get[AS] - for example getProfile(finder). The finder object is passed to `target.find`.
* * set[AS] - for example setProfile(instance, options). Options are passed to `target.save`
* * create[AS] - for example createProfile(value, options). Builds and saves a new instance of the associated model. Values and options are passed on to `target.create`
*
* All methods return a promise
*
* @method hasOne * @method hasOne
* @param {Model} target * @param {Model} target
* @param {object} [options] * @param {object} [options]
...@@ -150,14 +133,6 @@ Mixin.hasOne = singleLinked(HasOne); ...@@ -150,14 +133,6 @@ Mixin.hasOne = singleLinked(HasOne);
* *
* Example: `Profile.belongsTo(User)`. This will add userId to the profile table. * Example: `Profile.belongsTo(User)`. This will add userId to the profile table.
* *
* The following methods are injected on the source:
*
* * get[AS] - for example getUser(finder). The finder object is passed to `target.find`.
* * set[AS] - for example setUser(instance, options). Options are passed to this.save
* * create[AS] - for example createUser(value, options). Builds and saves a new instance of the associated model. Values and options are passed on to target.create
*
* All methods return a promise
*
* @method belongsTo * @method belongsTo
* @param {Model} target * @param {Model} target
* @param {object} [options] * @param {object} [options]
...@@ -185,22 +160,7 @@ Mixin.belongsTo = singleLinked(BelongsTo); ...@@ -185,22 +160,7 @@ Mixin.belongsTo = singleLinked(BelongsTo);
* ``` * ```
* By default, the name of the join table will be source+target, so in this case projectsusers. This can be overridden by providing either a string or a Model as `through` in the options. * By default, the name of the join table will be source+target, so in this case projectsusers. This can be overridden by providing either a string or a Model as `through` in the options.
* The following methods are injected on the source: * If you use a through model with custom attributes, these attributes can be set when adding / setting new associations in two ways. Consider users and projects from before with a join table that stores whether the project has been started yet:
*
* * get[AS] - for example getPictures(finder). The finder object is passed to `target.find`.
* * set[AS] - for example setPictures(instances, defaultAttributes|options). Update the associations. All currently associated models that are not in instances will be removed.
* * add[AS] - for example addPicture(instance, defaultAttributes|options). Add another associated object.
* * add[AS] [plural] - for example addPictures([instance1, instance2], defaultAttributes|options). Add some more associated objects.
* * create[AS] - for example createPicture(values, options). Build and save a new association.
* * remove[AS] - for example removePicture(instance). Remove a single association.
* * remove[AS] [plural] - for example removePictures(instance). Remove multiple association.
* * has[AS] - for example hasPicture(instance). Is source associated to this target?
* * has[AS] [plural] - for example hasPictures(instances). Is source associated to all these targets?
*
* All methods return a promise
*
* If you use a through model with custom attributes, these attributes can be set when adding / setting new associations in two ways. Consider users and projects from before
* with a join table that stores whether the project has been started yet:
* ```js * ```js
* var UserProjects = sequelize.define('userprojects', { * var UserProjects = sequelize.define('userprojects', {
* started: Sequelize.BOOLEAN * started: Sequelize.BOOLEAN
...@@ -277,23 +237,8 @@ Mixin.hasMany = function(targetModel, options) { // testhint options:none ...@@ -277,23 +237,8 @@ Mixin.hasMany = function(targetModel, options) { // testhint options:none
* Project.belongsToMany(User) * Project.belongsToMany(User)
* ``` * ```
* By default, the name of the join table will be source+target, so in this case projectsusers. This can be overridden by providing either a string or a Model as `through` in the options. * By default, the name of the join table will be source+target, so in this case projectsusers. This can be overridden by providing either a string or a Model as `through` in the options.
*
* The following methods are injected on the source: * If you use a through model with custom attributes, these attributes can be set when adding / setting new associations in two ways. Consider users and projects from before with a join table that stores whether the project has been started yet:
*
* * get[AS] - for example getPictures(finder). The finder object is passed to `target.find`.
* * set[AS] - for example setPictures(instances, defaultAttributes|options). Update the associations. All currently associated models that are not in instances will be removed.
* * add[AS] - for example addPicture(instance, defaultAttributes|options). Add another associated object.
* * add[AS] [plural] - for example addPictures([instance1, instance2], defaultAttributes|options). Add some more associated objects.
* * create[AS] - for example createPicture(values, options). Build and save a new association.
* * remove[AS] - for example removePicture(instance). Remove a single association.
* * remove[AS] [plural] - for example removePictures(instance). Remove multiple association.
* * has[AS] - for example hasPicture(instance). Is source associated to this target?
* * has[AS] [plural] - for example hasPictures(instances). Is source associated to all these targets?
*
* All methods return a promise
*
* If you use a through model with custom attributes, these attributes can be set when adding / setting new associations in two ways. Consider users and projects from before
* with a join table that stores whether the project has been started yet:
* ```js * ```js
* var UserProjects = sequelize.define('userprojects', { * var UserProjects = sequelize.define('userprojects', {
* started: Sequelize.BOOLEAN * started: Sequelize.BOOLEAN
......
...@@ -4,6 +4,7 @@ repo_url: https://github.com/sequelize/sequelize ...@@ -4,6 +4,7 @@ repo_url: https://github.com/sequelize/sequelize
site_favicon: favicon.ico site_favicon: favicon.ico
site_url: http://docs.sequelizejs.com site_url: http://docs.sequelizejs.com
markdown_extensions: [gfm] markdown_extensions: [gfm]
theme: readthedocs
extra_css: extra_css:
- css/custom.css - css/custom.css
extra_javascript: extra_javascript:
...@@ -29,7 +30,12 @@ pages: ...@@ -29,7 +30,12 @@ pages:
- 'Sequelize': 'api/sequelize.md' - 'Sequelize': 'api/sequelize.md'
- 'Model': 'api/model.md' - 'Model': 'api/model.md'
- 'Instance': 'api/instance.md' - 'Instance': 'api/instance.md'
- 'Associations': 'api/associations.md' - Associations:
- Overview: 'api/associations/index.md'
- 'BelongsTo (1:1)': 'api/associations/belongs-to.md'
- 'HasOne (1:1)': 'api/associations/has-one.md'
- 'HasMany (1:m)': 'api/associations/has-many.md'
- 'BelongsToMany (n:m)': 'api/associations/belongs-to-many.md'
- 'Hooks': 'api/hooks.md' - 'Hooks': 'api/hooks.md'
- 'Transaction': 'api/transaction.md' - 'Transaction': 'api/transaction.md'
- 'Datatypes': 'api/datatypes.md' - 'Datatypes': 'api/datatypes.md'
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!