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:
```js
...
...
@@ -204,7 +203,7 @@ sequelize.define('user', {
password:{
type:DataTypes.VIRTUAL,
set:function(val){
this.setDataValue('password',val);
this.setDataValue('password',val);// Remember to set the data value, otherwise it won't be validated
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.
...
...
@@ -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`).
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.
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.
...
...
@@ -199,7 +200,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.
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,7 +236,7 @@ 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.
...
...
@@ -320,7 +321,7 @@ 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
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.
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:
...
...
@@ -11,7 +11,7 @@ A Model represents a table in the database. Sometimes you might also see it refe
@@ -207,7 +207,7 @@ 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.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.paranoid=true] | Boolean | If false, will include columns which have a non-null deletedAt column. |
| [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[].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 |
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.
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
...
...
@@ -539,7 +539,7 @@ To obtain Instances for the newly created values, you will need to query for the
Delete multiple instances, or set their deletedAt timestamp to the current time if `paranoid` is enabled.
...
...
@@ -550,7 +550,7 @@ Delete multiple instances, or set their deletedAt timestamp to the current time
| options | Object | |
| [options.where] | Object | Filter the destroy |
| [options.hooks=true] | Boolean | Run before / after bulk destroy hooks? |
| [options.individualHooks=false] | Boolean | If set to true, destroy will find all records within the where parameter and will execute before / after bulkDestroy hooks on each row |
| [options.individualHooks=false] | Boolean | If set to true, destroy will SELECT all records matching the where parameter and will execute before / after destroy hooks on each row |
| [options.limit] | Number | How many rows to delete |
| [options.force=false] | Boolean | Delete instead of setting deletedAt to current timestamp (only applicable if `paranoid` is enabled) |
| [options.truncate=false] | Boolean | If set to true, dialects that support it will use TRUNCATE instead of DELETE FROM. If a table is truncated the where and limit options are ignored |
...
...
@@ -562,7 +562,7 @@ Delete multiple instances, or set their deletedAt timestamp to the current time
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.)
...
...
@@ -596,7 +596,7 @@ of affected rows, while the second element is the actual affected rows (only sup
| options.where | Object | Options to describe the scope of the search. |
| [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.individualHooks=false] | Boolean | Run before / after 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.returning=false] | Boolean | Return the affected rows (only for postgres) |
| [options.limit] | Number | How many rows to update (only for mysql and mariadb) |
| [options.transaction] | Transaction | |
...
...
@@ -606,7 +606,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.
...
...
@@ -15,7 +15,7 @@ If you want to propagate SQL events across `then`, `all` calls etc., you must us
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:**
...
...
@@ -119,7 +119,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.
**See:**
...
...
@@ -150,7 +150,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.
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:
...
...
@@ -485,7 +485,7 @@ For more about validation, see http://sequelizejs.com/docs/latest/models#validat
| [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[].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, 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.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.deletedAt] | String | Boolean | Override the name of the deletedAt column if a string is provided, or disable it if false. Timestamps must be true |
...
...
@@ -508,7 +508,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.
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.
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.
**See:**
...
...
@@ -790,7 +790,7 @@ Creates a object representing a column in the DB. This is often useful in conjun
Creates an object representing nested where conditions for postgres's json data-type.
**See:**
...
...
@@ -873,14 +873,14 @@ Creates an object representing nested where conditions for postgres's json data-
| Name | Type | Description |
| ---- | ---- | ----------- |
| conditions | String | Object | A hash containing strings/numbers or other nested hash, a string using dot notation or a string using postgres json syntax. |
| [value] | String | Number | Boolean | An optional value to compare against. Produces a string of the form "<jsonpath> = '<value>'". |
| [value] | String | Number | Boolean | An optional value to compare against. Produces a string of the form "<json path> = '<value>'". |
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
...
...
@@ -964,4 +964,4 @@ Note, that CLS is enabled for all sequelize instances, and all instances will sh
***
_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)_