-[BUG]fix showIndexQuery so appropriate indexes are returned when a schema is used
-[BUG]Fix showIndexQuery so appropriate indexes are returned when a schema is used
-[BUG] Fix addIndexQuery error when the model has a schema
-[BUG] Fix addIndexQuery error when the model has a schema
-[BUG] Fix app crash in sqlite while running in special unique constraint errors [3730](https://github.com/sequelize/sequelize/pull/3730)
-[BUG] Fix app crash in sqlite while running in special unique constraint errors [3730](https://github.com/sequelize/sequelize/pull/3730)
-[BUG] Fix API doc generation
#### Backwards compatibility changes
- The error that is thrown when a column is declared to be an enum but without any values used to "Values for ENUM haven't been defined" and is now "Values for ENUM have not been defined".
# 2.1.3
# 2.1.3
-[BUG] Fix regression introduced in 2.1.2: updatedAt not set anymore [3667](https://github.com/sequelize/sequelize/pull/3667)
-[BUG] Fix regression introduced in 2.1.2: updatedAt not set anymore [3667](https://github.com/sequelize/sequelize/pull/3667)
...
@@ -189,7 +193,7 @@
...
@@ -189,7 +193,7 @@
-[FEATURE] Added `find()` hooks
-[FEATURE] Added `find()` hooks
#### Backwards compatibility changes
#### Backwards compatibility changes
- The `fieldName` property, used in associations with a foreign key object `(A.hasMany(B, { foreignKey: { ... }})`, has been renamed to `name` to avoid confusion with `field`.
- The `fieldName` property, used in associations with a foreign key object `(A.hasMany(B, { foreignKey: { ... }})`, has been renamed to `name` to avoid confusion with `field`.
- The naming of the join table entry for N:M association getters is now singular (like includes)
- The naming of the join table entry for N:M association getters is now singular (like includes)
- Signature of hooks has changed to pass options to all hooks. Any hooks previously defined like `Model.beforeCreate(values)` now need to be `Model.beforeCreate(values, options)` etc.
- Signature of hooks has changed to pass options to all hooks. Any hooks previously defined like `Model.beforeCreate(values)` now need to be `Model.beforeCreate(values, options)` etc.
- Results returned by hooks are ignored - changes to results by hooks should be made by reference
- Results returned by hooks are ignored - changes to results by hooks should be made by reference
...
@@ -212,7 +216,7 @@ We are working our way to the first 2.0.0 release candidate.
...
@@ -212,7 +216,7 @@ We are working our way to the first 2.0.0 release candidate.
-[BUG] Fix default scope being overwritten [#2087](https://github.com/sequelize/sequelize/issues/2087)
-[BUG] Fix default scope being overwritten [#2087](https://github.com/sequelize/sequelize/issues/2087)
-[BUG] Fixed updatedAt timestamp not being set in bulk create when validate = true. [#1962](https://github.com/sequelize/sequelize/issues/1962)
-[BUG] Fixed updatedAt timestamp not being set in bulk create when validate = true. [#1962](https://github.com/sequelize/sequelize/issues/1962)
-[INTERNALS] Replaced lingo with inflection
-[INTERNALS] Replaced lingo with inflection
-[INTERNALS] Removed underscore.string dependency and moved a couple of helper functions from `Utils._` to `Utils`
-[INTERNALS] Removed underscore.string dependency and moved a couple of helper functions from `Utils._` to `Utils`
jan.addProject(homework,{started:false})// The homework project is not started yet
jan.addProject(homework,{started:false})// The homework project is not started yet
jan.setProjects([makedinner,doshopping],{started:true})// Both shopping and dinner has been started
jan.setProjects([makedinner,doshopping],{started:true})// Both shopping and dinner have been started
```
```
If you want to set several target instances, but with different attributes you have to set the attributes on the instance, using a property with the name of the through model:
If you want to set several target instances, but with different attributes you have to set the attributes on the instance, using a property with the name of the through model:
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',{
...
@@ -10,7 +10,8 @@ sequelize.define('model', {
...
@@ -10,7 +10,8 @@ sequelize.define('model', {
When defining a model you can just as easily pass a string as type, but often using the types defined here is beneficial. For example, using `DataTypes.BLOB`, mean
When defining a model you can just as easily pass a string as type, but often using the types defined here is beneficial. For example, using `DataTypes.BLOB`, mean
that that column will be returned as an instance of `Buffer` when being fetched by sequelize.
that that column will be returned as an instance of `Buffer` when being fetched by sequelize.
Some data types have special properties that can be accessed in order to change the data type. For example, to get an unsigned integer with zerofill you can do `DataTypes.INTEGER.UNSIGNED.ZEROFILL`.
Some data types have special properties that can be accessed in order to change the data type.
For example, to get an unsigned integer with zerofill you can do `DataTypes.INTEGER.UNSIGNED.ZEROFILL`.
The order you access the properties in do not matter, so `DataTypes.INTEGER.ZEROFILL.UNSIGNED` is fine as well. The available properties are listed under each data type.
The order you access the properties in do not matter, so `DataTypes.INTEGER.ZEROFILL.UNSIGNED` is fine as well. The available properties are listed under each data type.
To provide a length for the data type, you can invoke it like a function: `INTEGER(2)`
To provide a length for the data type, you can invoke it like a function: `INTEGER(2)`
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:
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.
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.
...
@@ -156,9 +156,13 @@ will be called instead. To bypass the setter, you can pass `raw: true` in the op
...
@@ -156,9 +156,13 @@ will be called instead. To bypass the setter, you can pass `raw: true` in the op
If set is called with an object, it will loop over the object, and call set recursively for each key, value pair. If you set raw to true, the underlying dataValues will either be
If set is called with an object, it will loop over the object, and call set recursively for each key, value pair. If you set raw to true, the underlying dataValues will either be
set directly to the object passed, or used to extend dataValues, if dataValues already contain values.
set directly to the object passed, or used to extend dataValues, if dataValues already contain values.
When set is called, the previous value of the field is stored, so that you can later see which fields changed (see `changed`).
When set is called, the previous value of the field is stored and sets a changed flag(see `changed`).
Set can also be used to build instances for associations, if you have values for those. TODO - mick should probably write something here about how includes in set works - perhaps also even some tests?
Set can also be used to build instances for associations, if you have values for those.
When using set with associations you need to make sure the property key matches the alias of the association
while also making sure that the proper include options have been set (from .build() or .find())
If called with a dot.seperated key on a JSON/JSONB attribute it will set the value nested and flag the entire object as changed.
**See:**
**See:**
...
@@ -175,7 +179,6 @@ Set can also be used to build instances for associations, if you have values for
...
@@ -175,7 +179,6 @@ Set can also be used to build instances for associations, if you have values for
| [options] | Object | |
| [options] | Object | |
| [options.raw=false] | Boolean | If set to true, field and virtual setters will be ignored |
| [options.raw=false] | Boolean | If set to true, field and virtual setters will be ignored |
| [options.reset=false] | Boolean | Clear all previously set data values |
| [options.reset=false] | Boolean | Clear all previously set data values |
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.
If changed is called without an argument and no keys have changed, it will return `false`.
**Params:**
**Params:**
...
@@ -200,7 +205,7 @@ If changed is called without an argument, it will return an array of keys that h
...
@@ -200,7 +205,7 @@ If changed is called without an argument, it will return an array of keys that h
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`.
...
@@ -235,8 +240,8 @@ This error will have a property for each of the fields for which validation fail
...
@@ -235,8 +240,8 @@ This error will have a property for each of the fields for which validation fail
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.
...
@@ -320,8 +325,8 @@ Destroy the row corresponding to this instance. Depending on your setting for pa
...
@@ -320,8 +325,8 @@ Destroy the row corresponding to this instance. Depending on your setting for pa
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
| fields | String | Array | Object | If a string is provided, that column is incremented by the value of `by` given in options. If an array is provided, the same is true for each column. If and object is provided, each column is incremented by the value given |
| fields | String | Array | Object | If a string is provided, that column is incremented by the value of `by` given in options. If an array is provided, the same is true for each column. If and object is provided, each column is incremented by the value given. |
| [options] | Object | |
| [options] | Object | |
| [options.by=1] | Integer | The number to increment by |
| [options.by=1] | Integer | The number to increment by |
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
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 Model represents a table in the database. Sometimes you might also see it refererred to as model, or simply as factory. This class should _not_ be instantiated directly, it is created using `sequelize.define`, and already created models can be loaded using `sequelize.import`
A Model represents a table in the database. Sometimes you might also see it refererred to as model, or simply as factory.
This class should _not_ be instantiated directly, it is created using `sequelize.define`, and already created models can be loaded using `sequelize.import`
### Mixes:
### Mixes:
* Hooks
* Hooks
...
@@ -11,7 +12,7 @@ A Model represents a table in the database. Sometimes you might also see it refe
...
@@ -11,7 +12,7 @@ A Model represents a table in the database. Sometimes you might also see it refe
| options* | Array | Object | String | null | The scope(s) to apply. Scopes can either be passed as consecutive arguments, or as an array of arguments. To apply simple scopes, pass them as strings. For scope function, pass an object, with a `method` property. The value can either be a string, if the method does not take any arguments, or an array, where the first element is the name of the method, and consecutive elements are arguments to that method. Pass null to remove all scopes, including the default. |
| options* | Array | Object | String | The scope(s) to apply. Scopes can either be passed as consecutive arguments, or as an array of arguments. To apply simple scopes and scope functions with no arguments, pass them as strings. For scope function, pass an object, with a `method` property. The value can either be a string, if the method does not take any arguments, or an array, where the first element is the name of the method, and consecutive elements are arguments to that method. Pass null to remove all scopes, including the default. |
__Returns:__ A reference to the model, with the scope(s) applied. Calling scope again on the returned model will clear the previous scope.
__Returns:__ A reference to the model, with the scope(s) applied. Calling scope again on the returned model will clear the previous scope.
@@ -206,30 +221,32 @@ The success listener is called with an array of instances if the query succeeds.
...
@@ -206,30 +221,32 @@ The success listener is called with an array of instances if the query succeeds.
| ---- | ---- | ----------- |
| ---- | ---- | ----------- |
| [options] | Object | A hash of options to describe the scope of the search |
| [options] | Object | A hash of options to describe the scope of the search |
| [options.where] | Object | A hash of attributes to describe your search. See above for examples. |
| [options.where] | Object | A hash of attributes to describe your search. See above for examples. |
| [options.attributes] | Array<String> | A list of the attributes that you want to select. To rename an attribute, you can pass an array, with two elements - the first is the name of the attribute in the DB (or some kind of expression such as `Sequelize.literal`, `Sequelize.fn` and so on), and the second is the name you want the attribute to have in the returned instance |
| [options.attributes] | Array.<String> | A list of the attributes that you want to select. To rename an attribute, you can pass an array, with two elements - the first is the name of the attribute in the DB (or some kind of expression such as `Sequelize.literal`, `Sequelize.fn` and so on), and the second is the name you want the attribute to have in the returned instance |
| [options.paranoid=true] | Boolean | If true, only non-deleted records will be returned. If false, both deleted and non-deleted records will be returned. Only applies if `options.paranoid` is true for the model. |
| [options.paranoid=true] | Boolean | If true, only non-deleted records will be returned. If false, both deleted and non-deleted records will be returned. Only applies if `options.paranoid` is true for the model. |
| [options.include] | Array<Object | Model> | A list of associations to eagerly load using a left join. Supported is either `{ include: [ Model1, Model2, ...]}` or `{ include: [{ model: Model1, as: 'Alias' }]}`. If your association are set up with an `as` (eg. `X.hasMany(Y, { as: 'Z }`, you need to specify Z in the as attribute when eager loading Y). |
| [options.include] | Array.<Object | Model> | A list of associations to eagerly load using a left join. Supported is either `{ include: [ Model1, Model2, ...]}` or `{ include: [{ model: Model1, as: 'Alias' }]}`. If your association are set up with an `as` (eg. `X.hasMany(Y, { as: 'Z }`, you need to specify Z in the as attribute when eager loading Y). |
| [options.include[].model] | Model | The model you want to eagerly load |
| [options.include[].model] | Model | The model you want to eagerly load |
| [options.include[].as] | String | The alias of the relation, in case the model you want to eagerly load is aliassed. For `hasOne` / `belongsTo`, this should be the singular name, and for `hasMany`, it should be the plural |
| [options.include[].as] | String | The alias of the relation, in case the model you want to eagerly load is aliassed. For `hasOne` / `belongsTo`, this should be the singular name, and for `hasMany`, it should be the plural |
| [options.include[].association] | Association | The association you want to eagerly load. (This can be used instead of providing a model/as pair) |
| [options.include[].association] | Association | The association you want to eagerly load. (This can be used instead of providing a model/as pair) |
| [options.include[].where] | Object | Where clauses to apply to the child models. Note that this converts the eager load to an inner join, unless you explicitly set `required: false` |
| [options.include[].where] | Object | Where clauses to apply to the child models. Note that this converts the eager load to an inner join, unless you explicitly set `required: false` |
| [options.include[].attributes] | Array<String> | A list of attributes to select from the child model |
| [options.include[].attributes] | Array.<String> | A list of attributes to select from the child model |
| [options.include[].required] | Boolean | If true, converts to an inner join, which means that the parent model will only be loaded if it has any matching children. True if `include.where` is set, false otherwise. |
| [options.include[].required] | Boolean | If true, converts to an inner join, which means that the parent model will only be loaded if it has any matching children. True if `include.where` is set, false otherwise. |
| [options.include[].include] | Array<Object | Model> | Load further nested related models |
| [options.include[].through.where] | Object | Filter on the join model for belongsToMany relations |
| [options.order] | String | Array | Sequelize.fn | Specifies an ordering. If a string is provided, it will be esacped. Using an array, you can provide several columns / functions to order by. Each element can be further wrapped in a two-element array. The first element is the column / function to order by, the second is the direction. For example: `order: [['name', 'DESC']]`. In this way the column will be escaped, but the direction will not. |
| [options.include[].through.attributes] | Array | A list of attributes to select from the join model for belongsToMany relations |
| [options.include[].include] | Array.<Object | Model> | Load further nested related models |
| [options.order] | String | Array | Sequelize.fn | Specifies an ordering. If a string is provided, it will be escaped. Using an array, you can provide several columns / functions to order by. Each element can be further wrapped in a two-element array. The first element is the column / function to order by, the second is the direction. For example: `order: [['name', 'DESC']]`. In this way the column will be escaped, but the direction will not. |
| [options.limit] | Number | |
| [options.limit] | Number | |
| [options.offset] | Number | |
| [options.offset] | Number | |
| [options.transaction] | Transaction | |
| [options.transaction] | Transaction | |
| [queryOptions] | Object | Set the query options, e.g. raw, specifying that you want raw data instead of built Instances. See sequelize.query for options |
| [options.lock] | String | Object | Lock the selected rows. Possible options are transaction.LOCK.UPDATE and transaction.LOCK.SHARE. Postgres also supports transaction.LOCK.KEY_SHARE, transaction.LOCK.NO_KEY_UPDATE and specific model locks with joins. See [transaction.LOCK for an example](api/transaction#lock) |
| [queryOptions.lock] | String|Object | Lock the selected rows. Possible options are transaction.LOCK.UPDATE and transaction.LOCK.SHARE. Postgres also supports transaction.LOCK.KEY_SHARE, transaction.LOCK.NO_KEY_UPDATE and specific model locks with joins. See [transaction.LOCK for an example](api/transaction#lock) |
| [options.raw] | Boolean | Return raw result. See sequelize.query for more information. |
Find all the rows matching your query, within a specified offset / limit, and get the total number of rows matching your query. This is very usefull for paging
Find all the rows matching your query, within a specified offset / limit, and get the total number of rows matching your query. This is very usefull for paging
Insert or update a single row. An update will be executed if a row which matches the supplied values on either the primary key or a unique key is found. Note that the unique index must be defined in your sequelize model and not just in the table. Otherwise you may experience a unique constraint violation, because sequelize fails to identify the row that should be updated.
Insert or update a single row. An update will be executed if a row which matches the supplied values on either the primary key or a unique key is found. Note that the unique index must be defined in your sequelize model and not just in the table. Otherwise you may experience a unique constraint violation, because sequelize fails to identify the row that should be updated.
The success handler is passed an array of instances, but please notice that these may not completely represent the state of the rows in the DB. This is because MySQL
The success handler is passed an array of instances, but please notice that these may not completely represent the state of the rows in the DB. This is because MySQL
...
@@ -538,8 +555,8 @@ To obtain Instances for the newly created values, you will need to query for the
...
@@ -538,8 +555,8 @@ To obtain Instances for the newly created values, you will need to query for the
Update multiple instances that match the where options. The promise returns an array with one or two elements. The first element is always the number
Update multiple instances that match the where options. The promise returns an array with one or two elements. The first element is always the number
of affected rows, while the second element is the actual affected rows (only supported in postgres with `options.returning` true.)
of affected rows, while the second element is the actual affected rows (only supported in postgres with `options.returning` true.)
...
@@ -594,6 +611,7 @@ of affected rows, while the second element is the actual affected rows (only sup
...
@@ -594,6 +611,7 @@ of affected rows, while the second element is the actual affected rows (only sup
| values | Object | |
| values | Object | |
| options | Object | |
| options | Object | |
| options.where | Object | Options to describe the scope of the search. |
| options.where | Object | Options to describe the scope of the search. |
| [options.fields] | Array | Fields to update (defaults to all fields) |
| [options.validate=true] | Boolean | Should each row be subject to validation before it is inserted. The whole insert will fail if one row fails validation |
| [options.validate=true] | Boolean | Should each row be subject to validation before it is inserted. The whole insert will fail if one row fails validation |
| [options.hooks=true] | Boolean | Run before / after bulk update hooks? |
| [options.hooks=true] | Boolean | Run before / after bulk update hooks? |
| [options.individualHooks=false] | Boolean | Run before / after update hooks?. If true, this will execute a SELECT followed by individual UPDATEs. A select is needed, because the row data needs to be passed to the hooks |
| [options.individualHooks=false] | Boolean | Run before / after update hooks?. If true, this will execute a SELECT followed by individual UPDATEs. A select is needed, because the row data needs to be passed to the hooks |
...
@@ -606,7 +624,7 @@ of affected rows, while the second element is the actual affected rows (only sup
...
@@ -606,7 +624,7 @@ of affected rows, while the second element is the actual affected rows (only sup
A slightly modified version of bluebird promises. This means that, on top of the methods below, you can also call all the methods listed on the link below.
The main difference is that sequelize promises allows you to attach a listener that will be called with the generated SQL, each time a query is run.
The sequelize promise class works seamlessly with other A+/thenable libraries, with one exception.
If you want to propagate SQL events across `then`, `all` calls etc., you must use sequelize promises exclusively.
| promise | SequelizePromise | The promise that should receive the events. |
| [options] | Object | |
| [options.events] | Array | An array of the events to proxy. Defaults to sql, error and success |
***
_This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on <a href="irc://irc.freenode.net/#sequelizejs">IRC</a>, open an issue or a create a pull request if you feel something can be improved. For help on how to write source code documentation see [JSDoc](http://usejsdoc.org) and [dox](https://github.com/tj/dox)_
_This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on <a href="irc://irc.freenode.net/#sequelizejs">IRC</a>, open an issue or a create a pull request if you feel something can be improved. For help on how to write source code documentation see [JSDoc](http://usejsdoc.org) and [dox](https://github.com/tj/dox)_
Instantiate sequelize with name of database, username and password
Instantiate sequelize with name of database, username and password
#### Example usage
#### Example usage
...
@@ -65,15 +65,16 @@ var sequelize = new Sequelize('mysql://localhost:3306/database', {})
...
@@ -65,15 +65,16 @@ var sequelize = new Sequelize('mysql://localhost:3306/database', {})
| [options.pool.maxConnections] | Integer | |
| [options.pool.maxConnections] | Integer | |
| [options.pool.minConnections] | Integer | |
| [options.pool.minConnections] | Integer | |
| [options.pool.maxIdleTime] | Integer | The maximum time, in milliseconds, that a connection can be idle before being released |
| [options.pool.maxIdleTime] | Integer | The maximum time, in milliseconds, that a connection can be idle before being released |
| [options.pool.validateConnection] | Function | A function that validates a connection. Called with client. The default function checks that client is an object, and that its state is not disconnected |
| [options.pool.validateConnection] | Function | A function that validates a connection. Called with client. The default function checks that client is an object, and that its state is not disconnected |
| [options.quoteIdentifiers=true] | Boolean | Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of them. |
| [options.quoteIdentifiers=true] | Boolean | Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of them. |
| [options.isolationLevel='REPEATABLE_READ'] | String | Set the default transaction isolation level. See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options. |
A reference to sequelize utilities. Most users will not need to use these utils directly. However, you might want to use `Sequelize.Utils._`, which is a reference to the lodash library, if you don't already have it imported in your project.
A reference to sequelize utilities. Most users will not need to use these utils directly. However, you might want to use `Sequelize.Utils._`, which is a reference to the lodash library, if you don't already have it imported in your project.
**See:**
**See:**
...
@@ -119,7 +120,7 @@ A reference to sequelize utilities. Most users will not need to use these utils
...
@@ -119,7 +120,7 @@ A reference to sequelize utilities. Most users will not need to use these utils
Exposes the validator.js object, so you can extend it with custom validation functions. The validator is exposed both on the instance, and on the constructor.
Exposes the validator.js object, so you can extend it with custom validation functions. The validator is exposed both on the instance, and on the constructor.
**See:**
**See:**
...
@@ -150,7 +151,7 @@ Exposes the validator.js object, so you can extend it with custom validation fun
...
@@ -150,7 +151,7 @@ Exposes the validator.js object, so you can extend it with custom validation fun
Define a new model, representing a table in the DB.
Define a new model, representing a table in the DB.
The table columns are define by the hash that is given as the second argument. Each attribute of the hash represents a column. A short table definition might look like this:
The table columns are define by the hash that is given as the second argument. Each attribute of the hash represents a column. A short table definition might look like this:
...
@@ -430,13 +431,13 @@ sequelize.models.modelName // The model will now be available in models under th
...
@@ -430,13 +431,13 @@ sequelize.models.modelName // The model will now be available in models under th
As shown above, column definitions can be either strings, a reference to one of the datatypes that are predefined on the Sequelize constructor, or an object that allows you to specify both the type of the column, and other attributes such as default values, foreign key constraints and custom setters and getters.
As shown above, column definitions can be either strings, a reference to one of the datatypes that are predefined on the Sequelize constructor, or an object that allows you to specify both the type of the column, and other attributes such as default values, foreign key constraints and custom setters and getters.
For a list of possible data types, see http://sequelizejs.com/docs/latest/models#data-types
For a list of possible data types, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#data-types
For more about getters and setters, see http://sequelizejs.com/docs/latest/models#getters---setters
For more about getters and setters, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#getters-setters
For more about instance and class methods, see http://sequelizejs.com/docs/latest/models#expansion-of-models
For more about instance and class methods, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#expansion-of-models
For more about validation, see http://sequelizejs.com/docs/latest/models#validations
For more about validation, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#validations
**See:**
**See:**
...
@@ -479,16 +480,16 @@ For more about validation, see http://sequelizejs.com/docs/latest/models#validat
...
@@ -479,16 +480,16 @@ For more about validation, see http://sequelizejs.com/docs/latest/models#validat
| [options.name] | Object | An object with two attributes, `singular` and `plural`, which are used when this model is associated to others. |
| [options.name] | Object | An object with two attributes, `singular` and `plural`, which are used when this model is associated to others. |
| [options.indexes[].name] | String | The name of the index. Defaults to model name + _ + fields concatenated |
| [options.indexes[].name] | String | The name of the index. Defaults to model name + _ + fields concatenated |
| [options.indexes[].type] | String | Index type. Only used by mysql. One of `UNIQUE`, `FULLTEXT` and `SPATIAL` |
| [options.indexes[].type] | String | Index type. Only used by mysql. One of `UNIQUE`, `FULLTEXT` and `SPATIAL` |
| [options.indexes[].method] | String | The method to create the index by (`USING` statement in SQL). BTREE and HASH are supported by mysql and postgres, and postgres additionally supports GIST and GIN. |
| [options.indexes[].method] | String | The method to create the index by (`USING` statement in SQL). BTREE and HASH are supported by mysql and postgres, and postgres additionally supports GIST and GIN. |
| [options.indexes[].unique=false] | Boolean | Should the index by unique? Can also be triggered by setting type to `UNIQUE` |
| [options.indexes[].unique=false] | Boolean | Should the index by unique? Can also be triggered by setting type to `UNIQUE` |
| [options.indexes[].concurrently=false] | Boolean | PostgreSQL will build the index without taking any write locks. Postgres only |
| [options.indexes[].concurrently=false] | Boolean | PostgreSQL will build the index without taking any write locks. Postgres only |
| [options.indexes[].fields] | Array<String | Object> | An array of the fields to index. Each field can either be a string containing the name of the field, a sequelize object (e.g `sequelize.fn`), or an object with the following attributes: `attribute` (field name), `length` (create a prefix index of length chars), `order` (the direction the column should be sorted in), `collate` (the collation (sort order) for the column) |
| [options.indexes[].fields] | Array.<String | Object> | An array of the fields to index. Each field can either be a string containing the name of the field, a sequelize object (e.g `sequelize.fn`), or an object with the following attributes: `attribute` (field name), `length` (create a prefix index of length chars), `order` (the direction the column should be sorted in), `collate` (the collation (sort order) for the column) |
| [options.createdAt] | String | Boolean | Override the name of the createdAt column if a string is provided, or disable it if false. Timestamps must be true |
| [options.createdAt] | String | Boolean | Override the name of the createdAt column if a string is provided, or disable it if false. Timestamps must be true. Not affected by underscored setting. |
| [options.updatedAt] | String | Boolean | Override the name of the updatedAt column if a string is provided, or disable it if false. Timestamps must be true |
| [options.updatedAt] | String | Boolean | Override the name of the updatedAt column if a string is provided, or disable it if false. Timestamps must be true. Not affected by underscored setting. |
| [options.deletedAt] | String | Boolean | Override the name of the deletedAt column if a string is provided, or disable it if false. Timestamps must be true |
| [options.deletedAt] | String | Boolean | Override the name of the deletedAt column if a string is provided, or disable it if false. Timestamps must be true. Not affected by underscored setting. |
| [options.tableName] | String | Defaults to pluralized model name, unless freezeTableName is true, in which case it uses model name verbatim |
| [options.tableName] | String | Defaults to pluralized model name, unless freezeTableName is true, in which case it uses model name verbatim |
| [options.getterMethods] | Object | Provide getter functions that work like those defined per column. If you provide a getter method with the same name as a column, it will be used to access the value of that column. If you provide a name that does not match a column, this function will act as a virtual getter, that can fetch multiple other values |
| [options.getterMethods] | Object | Provide getter functions that work like those defined per column. If you provide a getter method with the same name as a column, it will be used to access the value of that column. If you provide a name that does not match a column, this function will act as a virtual getter, that can fetch multiple other values |
| [options.setterMethods] | Object | Provide setter functions that work like those defined per column. If you provide a setter method with the same name as a column, it will be used to update the value of that column. If you provide a name that does not match a column, this function will act as a virtual setter, that can act on and set other values, but will not be persisted |
| [options.setterMethods] | Object | Provide setter functions that work like those defined per column. If you provide a setter method with the same name as a column, it will be used to update the value of that column. If you provide a name that does not match a column, this function will act as a virtual setter, that can act on and set other values, but will not be persisted |
...
@@ -508,7 +509,7 @@ For more about validation, see http://sequelizejs.com/docs/latest/models#validat
...
@@ -508,7 +509,7 @@ For more about validation, see http://sequelizejs.com/docs/latest/models#validat
Execute a query on the DB, with the posibility to bypass all the sequelize goodness.
Execute a query on the DB, with the posibility to bypass all the sequelize goodness.
By default, the function will return two arguments: an array of results, and a metadata object, containing number of affected rows etc. Use `.spread` to access the results.
By default, the function will return two arguments: an array of results, and a metadata object, containing number of affected rows etc. Use `.spread` to access the results.
Creates a object representing a database function. This can be used in search queries, both in where and order parts, and as default values in column definitions.
Creates a object representing a database function. This can be used in search queries, both in where and order parts, and as default values in column definitions.
If you want to refer to columns in your function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and not a strings.
If you want to refer to columns in your function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and not a strings.
Creates a object representing a column in the DB. This is often useful in conjunction with `sequelize.fn`, since raw string arguments to fn will be escaped.
Creates a object representing a column in the DB. This is often useful in conjunction with `sequelize.fn`, since raw string arguments to fn will be escaped.
**See:**
**See:**
...
@@ -790,7 +812,7 @@ Creates a object representing a column in the DB. This is often useful in conjun
...
@@ -790,7 +812,7 @@ Creates a object representing a column in the DB. This is often useful in conjun
Start a transaction. When using transactions, you should pass the transaction in the options argument in order for the query to happen under that transaction
Start a transaction. When using transactions, you should pass the transaction in the options argument in order for the query to happen under that transaction
```js
```js
...
@@ -959,7 +981,7 @@ Note, that CLS is enabled for all sequelize instances, and all instances will sh
...
@@ -959,7 +981,7 @@ Note, that CLS is enabled for all sequelize instances, and all instances will sh
| ---- | ---- | ----------- |
| ---- | ---- | ----------- |
| [options={}] | Object | |
| [options={}] | Object | |
| [options.autocommit=true] | Boolean | |
| [options.autocommit=true] | Boolean | |
| [options.isolationLevel='REPEATABLE | String | READ'] See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options |
| [options.isolationLevel='REPEATABLE_READ'] | String | See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options |
* @param {Object options.where Options to describe the scope of the search.
* @param {Object} options.where Options to describe the scope of the search.
* @param {Array} [options.fields] Fields to update (defaults to all fields)
* @param {Array} [options.fields] Fields to update (defaults to all fields)
* @param {Boolean} [options.validate=true] Should each row be subject to validation before it is inserted. The whole insert will fail if one row fails validation
* @param {Boolean} [options.validate=true] Should each row be subject to validation before it is inserted. The whole insert will fail if one row fails validation
* @param {Boolean} [options.hooks=true] Run before / after bulk update hooks?
* @param {Boolean} [options.hooks=true] Run before / after bulk update hooks?