* 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
* @class BelongsToMany
* @memberof Associations
*/
classBelongsToManyextendsAssociation{
constructor(source,target,options){
...
...
@@ -204,38 +205,46 @@ class BelongsToMany extends Association {
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @param {String} [options.schema] Apply a schema on the related model
* @see {Model#findAll} for a full explanation of options
* @return {Promise<Array<Instance>>}
* @return {Promise<Array<Model>>}
* @method getAssociations
* @memberof Associations.BelongsToMany
* @instance
*/
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 persisted instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Array<Model|String|Number>} [newAssociations] An array of persisted 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
* @memberof Associations.BelongsToMany
* @instance
*/
set:'set'+plural,
/**
* Associate several persisted instances with this.
*
* @param {Array<Instance|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this.
* @param {Array<Model|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this.
* @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 addAssociations
* @memberof Associations.BelongsToMany
* @instance
*/
addMultiple:'add'+plural,
/**
* Associate a persisted instance with this.
*
* @param {Instance|String|Number} [newAssociation] A persisted instance or primary key of instance to associate with this.
* @param {Model|String|Number} [newAssociation] A persisted instance or primary key of instance to associate with this.
* @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
* @memberof Associations.BelongsToMany
* @instance
*/
add:'add'+singular,
/**
...
...
@@ -245,42 +254,52 @@ class BelongsToMany extends Association {
* @param {Object} [options] Options passed to create and add. Can also hold additional attributes for the join table
* @return {Promise}
* @method createAssociation
* @memberof Associations.BelongsToMany
* @instance
*/
create:'create'+singular,
/**
* Un-associate the instance.
*
* @param {Instance|String|Number} [oldAssociated] Can be an Instance or its primary key
* @param {Model|String|Number} [oldAssociated] Can be an Instance or its primary key
* @param {Object} [options] Options passed to `through.destroy`
* @return {Promise}
* @method removeAssociation
* @memberof Associations.BelongsToMany
* @instance
*/
remove:'remove'+singular,
/**
* Un-associate several instances.
*
* @param {Array<Instance|String|Number>} [oldAssociated] Can be an array of instances or their primary keys
* @param {Array<Model|String|Number>} [oldAssociated] Can be an array of instances or their primary keys
* @param {Object} [options] Options passed to `through.destroy`
* @return {Promise}
* @method removeAssociations
* @memberof Associations.BelongsToMany
* @instance
*/
removeMultiple:'remove'+plural,
/**
* Check if an instance is associated with this.
*
* @param {Instance|String|Number} [instance] Can be an Instance or its primary key
* @param {Model|String|Number} [instance] Can be an Instance or its primary key
* @param {Object} [options] Options passed to getAssociations
* @return {Promise}
* @method hasAssociation
* @memberof Associations.BelongsToMany
* @instance
*/
hasSingle:'has'+singular,
/**
* Check if all instances are associated with this.
*
* @param {Array<Instance|String|Number>} [instances] Can be an array of instances or their primary keys
* @param {Array<Model|String|Number>} [instances] Can be an array of instances or their primary keys
* @param {Object} [options] Options passed to getAssociations
* @return {Promise}
* @method hasAssociations
* @memberof Associations.BelongsToMany
* @instance
*/
hasAll:'has'+plural,
/**
...
...
@@ -289,8 +308,10 @@ class BelongsToMany extends Association {
* @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
@@ -11,7 +11,8 @@ const Association = require('./base');
*
* In the API reference below, replace `Assocation` with the actual name of your association, e.g. for `User.belongsTo(Project)` the getter will be `user.getProject()`.
*
* @mixin BelongsTo
* @class BelongsTo
* @memberof Associations
*/
classBelongsToextendsAssociation{
constructor(source,target,options){
...
...
@@ -78,19 +79,21 @@ class BelongsTo extends Association {
* @param {Object} [options]
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false.
* @param {String} [options.schema] Apply a schema on the related model
* @see {Model#findOne} for a full explanation of options
* @return {Promise<Instance>}
* @see {@link Model.findOne} for a full explanation of options
* @return {Promise<Model>}
* @method getAssociation
* @memberof Associations.BelongsTo
*/
get:'get'+singular,
/**
* Set the associated model.
*
* @param {Instance|String|Number} [newAssociation] An persisted instance or the primary key of an instance to associate with this. Pass `null` or `undefined` to remove the association.
* @param {Model|String|Number} [newAssociation] An persisted instance or the primary key of an instance to associate with this. Pass `null` or `undefined` to remove the association.
* @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
* @memberof Associations.BelongsTo
*/
set:'set'+singular,
/**
...
...
@@ -101,6 +104,7 @@ class BelongsTo extends Association {
* @see {Model#create} for a full explanation of options
@@ -10,7 +10,8 @@ const Association = require('./base');
*
* In the API reference below, replace `Association(s)` with the actual name of your association, e.g. for `User.hasMany(Project)` the getter will be `user.getProjects()`.
*
* @mixin HasMany
* @class HasMany
* @memberof Associations
*/
classHasManyextendsAssociation{
constructor(source,target,options){
...
...
@@ -98,38 +99,42 @@ class HasMany extends Association {
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @param {String} [options.schema] Apply a schema on the related model
* @see {Model#findAll} for a full explanation of options
* @return {Promise<Array<Instance>>}
* @return {Promise<Array<Model>>}
* @method getAssociations
* @memberof Associations.HasMany
*/
get:'get'+plural,
/**
* Set the associated models by passing an array of persisted instances or their primary keys. Everything that is not in the passed array will be un-associated
*
* @param {Array<Instance|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Array<Model|String|Number>} [newAssociations] An array of persisted 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
* @memberof Associations.HasMany
*/
set:'set'+plural,
/**
* Associate several persisted instances with this.
*
* @param {Array<Instance|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this.
* @param {Array<Model|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this.
* @param {Object} [options] Options passed to `target.update`.
* @param {Object} [options.validate] Run validation for the join model.
* @return {Promise}
* @method addAssociations
* @memberof Associations.HasMany
*/
addMultiple:'add'+plural,
/**
* Associate a persisted instance with this.
*
* @param {Instance|String|Number} [newAssociation] A persisted instance or primary key of instance to associate with this.
* @param {Model|String|Number} [newAssociation] A persisted instance or primary key of instance to associate with this.
* @param {Object} [options] Options passed to `target.update`.
* @param {Object} [options.validate] Run validation for the join model.
* @return {Promise}
* @method addAssociation
* @memberof Associations.HasMany
*/
add:'add'+singular,
/**
...
...
@@ -139,42 +144,47 @@ class HasMany extends Association {
* @param {Object} [options] Options passed to `target.create`.
* @return {Promise}
* @method createAssociation
* @memberof Associations.HasMany
*/
create:'create'+singular,
/**
* Un-associate the instance.
*
* @param {Instance|String|Number} [oldAssociated] Can be an Instance or its primary key
* @param {Model|String|Number} [oldAssociated] Can be an Instance or its primary key
* @param {Object} [options] Options passed to `target.update`
* @return {Promise}
* @method removeAssociation
* @memberof Associations.HasMany
*/
remove:'remove'+singular,
/**
* Un-associate several instances.
*
* @param {Array<Instance|String|Number>} [oldAssociatedArray] Can be an array of instances or their primary keys
* @param {Array<Model|String|Number>} [oldAssociatedArray] Can be an array of instances or their primary keys
* @param {Object} [options] Options passed to `through.destroy`
* @return {Promise}
* @method removeAssociations
* @memberof Associations.HasMany
*/
removeMultiple:'remove'+plural,
/**
* Check if an instance is associated with this.
*
* @param {Instance|String|Number} [instance] Can be an Instance or its primary key
* @param {Model|String|Number} [instance] Can be an Instance or its primary key
* @param {Object} [options] Options passed to getAssociations
* @return {Promise}
* @method hasAssociation
* @memberof Associations.HasMany
*/
hasSingle:'has'+singular,
/**
* Check if all instances are associated with this.
*
* @param {Array<Instance|String|Number>} [instances] Can be an array of instances or their primary keys
* @param {Array<Model|String|Number>} [instances] Can be an array of instances or their primary keys
* @param {Object} [options] Options passed to getAssociations
* @return {Promise}
* @method hasAssociations
* @memberof Associations.HasMany
*/
hasAll:'has'+plural,
/**
...
...
@@ -183,8 +193,9 @@ class HasMany extends Association {
* @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<Int>}
* @return {Promise<Integer>}
* @method countAssociations
* @memberof Associations.HasMany
*/
count:'count'+plural
};
...
...
@@ -333,7 +344,8 @@ class HasMany extends Association {
@@ -11,7 +11,8 @@ const Association = require('./base');
* In the API reference below, replace `Association` with the actual name of your association, e.g. for `User.hasOne(Project)` the getter will be `user.getProject()`.
* This is almost the same as `belongsTo` with one exception. The foreign key will be defined on the target model.
*
* @mixin HasOne
* @class HasOne
* @memberof Associations
*/
classHasOneextendsAssociation{
constructor(srcModel,targetModel,options){
...
...
@@ -76,8 +77,9 @@ class HasOne extends Association {
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @param {String} [options.schema] Apply a schema on the related model
* @see {Model#findOne} for a full explanation of options
* @return {Promise<Instance>}
* @return {Promise<Model>}
* @method getAssociation
* @memberof Associations.HasOne
*/
get:'get'+singular,
/**
...
...
@@ -87,6 +89,7 @@ class HasOne extends Association {
* @param {Object} [options] Options passed to getAssociation and `target.save`
* @return {Promise}
* @method setAssociation
* @memberof Associations.HasOne
*/
set:'set'+singular,
/**
...
...
@@ -97,6 +100,7 @@ class HasOne extends Association {
* @see {Model#create} for a full explanation of options
* 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.
*
* @mixin Associations
* @namespace Associations
* @name Associations
*/
constMixin={
...
...
@@ -101,6 +101,8 @@ const Mixin = {
* @param {string} [options.onDelete='SET NULL|CASCADE'] SET NULL if foreignKey allows nulls, CASCADE if otherwise
* @param {string} [options.onUpdate='CASCADE']
* @param {boolean} [options.constraints=true] Should on update and on delete constraints be enabled on the foreign key.
@@ -253,9 +253,9 @@ INTEGER.prototype.validate = function validate(value) {
*
* Note: an attribute defined as `BIGINT` will be treated like a `string` due this [feature from node-postgres](https://github.com/brianc/node-postgres/pull/353) to prevent precision loss. To have this attribute as a `number`, this is a possible [workaround](https://github.com/sequelize/sequelize/issues/2383#issuecomment-58006083).
*
* Available properties: `UNSIGNED`, `ZEROFILL`
*
* @property BIGINT
* @property UNSIGNED
* @property ZEROFILL
* @memberof DataTypes
*/
functionBIGINT(length){
...
...
@@ -277,9 +277,9 @@ BIGINT.prototype.validate = function validate(value) {
/**
* Floating point number (4-byte precision). Accepts one or two arguments for precision
* @property INITIALLY_DEFERRED Defer constraints checks to the end of transactions.
* @property INITIALLY_IMMEDIATE Trigger the constraint checks immediately
* @property NOT Set the constraints to not deferred. This is the default in PostgreSQL and it make it impossible to dynamically defer the constraints within a transaction.
*/
varDeferrable=module.exports={
INITIALLY_DEFERRED:INITIALLY_DEFERRED,
...
...
@@ -50,12 +55,6 @@ ABSTRACT.prototype.toString = function () {
returnthis.toSql.apply(this,arguments);
};
/**
* A property that will defer constraints checks to the end of transactions.
*
* @property INITIALLY_DEFERRED
*/
functionINITIALLY_DEFERRED(){
if(!(thisinstanceofINITIALLY_DEFERRED)){
returnnewINITIALLY_DEFERRED();
...
...
@@ -67,12 +66,6 @@ INITIALLY_DEFERRED.prototype.toSql = function () {
return'DEFERRABLE INITIALLY DEFERRED';
};
/**
* A property that will trigger the constraint checks immediately
*
* @property INITIALLY_IMMEDIATE
*/
functionINITIALLY_IMMEDIATE(){
if(!(thisinstanceofINITIALLY_IMMEDIATE)){
returnnewINITIALLY_IMMEDIATE();
...
...
@@ -84,14 +77,6 @@ INITIALLY_IMMEDIATE.prototype.toSql = function () {
return'DEFERRABLE INITIALLY IMMEDIATE';
};
/**
* A property that will set the constraints to not deferred. This is
* the default in PostgreSQL and it make it impossible to dynamically
* defer the constraints within a transaction.
*
* @property NOT
*/
functionNOT(){
if(!(thisinstanceofNOT)){
returnnewNOT();
...
...
@@ -109,7 +94,7 @@ NOT.prototype.toSql = function () {
* transaction which sets the constraints to deferred.
*
* @param {Array} constraints An array of constraint names. Will defer all constraints by default.
* @property SET_DEFERRED
* @memberof Sequelize.Deferrable
*/
functionSET_DEFERRED(constraints){
if(!(thisinstanceofSET_DEFERRED)){
...
...
@@ -130,7 +115,7 @@ SET_DEFERRED.prototype.toSql = function (queryGenerator) {
* transaction which sets the constraints to immediately.
*
* @param {Array} constraints An array of constraint names. Will defer all constraints by default.
* However, if getters and/or setters are defined for `field` they will be invoked, instead of returning the value from `dataValues`.
* Accessing properties directly or using `get` is preferred for regular use, `getDataValue` should only be used for custom getters.
*
* @see {Sequelize#define} for more information about getters and setters
* @see {@link Sequelize#define} for more information about getters and setters
* @class Model
* @mixes Hooks
* @mixes Associations
*/
classModel{
...
...
@@ -899,7 +898,7 @@ class Model {
/**
* Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model instance (this)
* @see {Sequelize#sync} for options
* @see {@link Sequelize#sync} for options
* @return {Promise<this>}
*/
staticsync(options){
...
...
@@ -973,7 +972,7 @@ class Model {
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
*
* @see {Sequelize#define} for more information about setting a default schema.
* @see {@link Sequelize#define} for more information about setting a default schema.
*
* @return {this}
*/
...
...
@@ -1088,7 +1087,7 @@ class Model {
* // WHERE email like 'dan@sequelize.com%' AND access_level >= 42
* ```
*
* @param {Array|Object|String|null} options* 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.
* @param {...Array|Object|String|null} options 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.
* @return {Model} A reference to the model, with the scope(s) applied. Calling scope again on the returned model will clear the previous scope.
*/
staticscope(option){
...
...
@@ -1220,7 +1219,9 @@ class Model {
* WHERE `Model`.`name` = 'a project' AND (`Model`.`id` IN (1, 2, 3) OR (`Model`.`id` > 10 AND `Model`.`id` < 100));
* ```
*
* The success listener is called with an array of instances if the query succeeds.
* The promise is resolved with an array of Model instances if the query succeeds.
*
* __Alias__: _all_
*
* @param {Object} [options] A hash of options to describe the scope of the search
* @param {Object} [options.where] A hash of attributes to describe your search. See above for examples.
...
...
@@ -1254,11 +1255,9 @@ class Model {
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {Boolean|Error} [options.rejectOnEmpty=false] Throws an error when no records found
* Because the include for `Profile` has `required` set it will result in an inner join, and only the users who have a profile will be counted. If we remove `required` from the include, both users with and without profiles will be counted
*
* __Alias__: _findAndCountAll_
*
* @param {Object} [findOptions] See findAll
*
* @see {Model#findAll} for a specification of find and query options
* @return {Promise<Object>}
* @alias findAndCountAll
* @see {@link Model#findAll} for a specification of find and query options
* Builds a new model instance and calls save on it.
* @see {Instance#build}
* @see {Instance#save}
* @see {@link Model#build}
* @see {@link Model#save}
*
* @param {Object} values
* @param {Object} [options]
...
...
@@ -1750,7 +1752,7 @@ class Model {
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {Boolean} [options.returning=true] Return the affected rows (only for postgres)
*
* @return {Promise<Instance>}
* @return {Promise<Model>}
*
*/
staticcreate(values,options){
...
...
@@ -1769,6 +1771,8 @@ class Model {
* Find a row that matches the query, or build (but don't save) the row if none is found.
* The successful result of the promise will be (instance, initialized) - Make sure to use .spread()
*
* __Alias__: _findOrInitialize_
*
* @param {Object} options
* @param {Object} options.where A hash of search attributes.
* @param {Object} [options.defaults] Default values to use if building a new instance
...
...
@@ -1776,8 +1780,7 @@ class Model {
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
*
* @return {Promise<Instance,initialized>}
* @alias findOrBuild
* @return {Promise<Model,initialized>}
*/
staticfindOrBuild(options){
if(!options||!options.where||arguments.length>1){
...
...
@@ -1817,8 +1820,8 @@ class Model {
* @param {Object} options.where where A hash of search attributes.
* @param {Object} [options.defaults] Default values to use if creating a new instance
* @param {Transaction} [options.transaction] Transaction to run query under
* @see {Model#findAll} for a full specification of find and options
* @return {Promise<Instance,created>}
* @see {@link Model#findAll} for a full specification of find and options
* @return {Promise<Model,created>}
*/
staticfindOrCreate(options){
if(!options||!options.where||arguments.length>1){
...
...
@@ -1910,8 +1913,8 @@ class Model {
* @param {Object} options
* @param {Object} options.where where A hash of search attributes.
* @param {Object} [options.defaults] Default values to use if creating a new instance
* @see {Model#findAll} for a full specification of find and options
* @return {Promise<Instance,created>}
* @see {@link Model#findAll} for a full specification of find and options
* @return {Promise<Model,created>}
*/
staticfindCreateFind(options){
if(!options||!options.where){
...
...
@@ -1946,6 +1949,8 @@ class Model {
*
* **Note** that SQLite returns undefined for created, no matter if the row was created or updated. This is because SQLite always runs INSERT OR IGNORE + UPDATE, in a single query, so there is no way to know whether the row was inserted or not.
*
* __Alias__: _insertOrUpdate_
*
* @param {Object} values
* @param {Object} [options]
* @param {Boolean} [options.validate=true] Run validations before the row is inserted
...
...
@@ -1956,7 +1961,6 @@ class Model {
* @param {Boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
*
* @alias insertOrUpdate
* @return {Promise<created>} Returns a boolean indicating whether the row was created or updated.
*/
staticupsert(values,options){
...
...
@@ -2172,7 +2176,7 @@ class Model {
*
* @return {Promise}
*
* @see {Model#destroy} for more information
* @see {@link Model#destroy} for more information
*/
statictruncate(options){
options=Utils.cloneDeep(options)||{};
...
...
@@ -2657,7 +2661,7 @@ class Model {
/**
* Returns the Model the instance was created from.
* @see {Model}
* @see {@link Model}
* @property Model
* @return {Model}
*/
...
...
@@ -2718,7 +2722,7 @@ class Model {
/**
* A reference to the sequelize instance
* @see {Sequelize}
* @see {@link Sequelize}
* @property sequelize
* @return {Sequelize}
*/
...
...
@@ -2846,13 +2850,12 @@ class Model {
*
* If called with a dot.separated key on a JSON/JSONB attribute it will set the value nested and flag the entire object as changed.
*
* @see {Model#find} for more information about includes
* @see {@link Model#find} for more information about includes
* @param {String|Object} key
* @param {any} value
* @param {Object} [options]
* @param {Boolean} [options.raw=false] If set to true, field and virtual setters will be ignored
* @param {Boolean} [options.reset=false] Clear all previously set data values
* @alias setAttributes
*/
set(key,value,options){// testhint options:none
letvalues;
...
...
@@ -3314,14 +3317,15 @@ class Model {
});
}
/*
/**
* 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,
* all references to the Instance are updated with the new data and no new objects are created.
*
* @see {Model#find}
* @see {@link Model#find}
* @param {Object} [options] Options that are passed on to `Model.find`
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
*
* @return {Promise<this>}
*/
reload(options){
...
...
@@ -3350,15 +3354,14 @@ class Model {
});
}
/*
* Validate the attribute of this instance according to validation rules set in the model definition.
/**
* Validate the attributes 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.
*
* @param {Object} [options] Options that are passed to the validator
* @param {Array} [options.skip] An array of strings. All properties that are in this array will not be validated
* @param {Boolean} [options.hooks=true] Run before and after validate hooks
* This is the same as calling `set` and then calling `save` but it only saves the
* exact values passed to it, making it more atomic and safer.
*
* @see {Instance#set}
* @see {Instance#save}
* @see {@link Model#set}
* @see {@link Model#save}
* @param {Object} updates See `set`
* @param {Object} options See `save`
*
* @return {Promise<this>}
* @alias updateAttributes
*/
update(values,options){
constchangedBefore=this.changed()||[];
...
...
@@ -3500,7 +3502,7 @@ class Model {
* // `by` is ignored, since each column has its own value
* ```
*
* @see {Instance#reload}
* @see {@link Model#reload}
* @param {String|Array|Object} fields 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.
* @param {Object} [options]
* @param {Integer} [options.by=1] The number to increment by
...
...
@@ -3562,7 +3564,7 @@ class Model {
* // `by` is ignored, since each column has its own value
* ```
*
* @see {Instance#reload}
* @see {@link Model#reload}
* @param {String|Array|Object} fields If a string is provided, that column is decremented 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 decremented by the value given
* @param {Object} [options]
* @param {Integer} [options.by=1] The number to decrement by
...
...
@@ -3591,7 +3593,7 @@ class Model {
/**
* Check whether this and `other` Instance refer to the same row
*
* @param {Instance} other
* @param {Model} other
* @return {Boolean}
*/
equals(other){
...
...
@@ -3624,7 +3626,7 @@ class Model {
/**
* 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.
* In addition to sequelize, the connection library for the dialect you want to use should also be installed in your project. You don't need to import it however, as sequelize will take care of that.
*
* @class Sequelize
* @lands Errors
*/
/**
...
...
@@ -239,7 +240,6 @@ class Sequelize {
/**
* Models are stored here under the name given to `sequelize.define`
* @property models
*/
this.models={};
this.modelManager=newModelManager(this);
...
...
@@ -283,8 +283,6 @@ class Sequelize {
* @method getQueryInterface
* @return {QueryInterface} An instance (singleton) of QueryInterface.
* For more about validation, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#validations
*
* @see {DataTypes}
* @see {Hooks}
* @see {@link DataTypes}
* @see {@link Hooks}
* @param {String} modelName The name of the model. The model will be stored in `sequelize.models` under this name
* @param {Object} attributes An object, where each attribute is a column of the table. Each column can be either a DataType, a string or a type-description object, with the properties described below:
* @param {String|DataType|Object} attributes.column The description of a database column
...
...
@@ -359,7 +357,7 @@ class Sequelize {
* @param {Boolean} [options.paranoid=false] Calling `destroy` will not delete the model, but instead set a `deletedAt` timestamp if this is true. Needs `timestamps=true` to work
* @param {Boolean} [options.underscored=false] Converts all camelCased columns to underscored if true
* @param {Boolean} [options.underscoredAll=false] Converts camelCased model names to underscored table names if true
* @param {Boolean} [options.freezeTableName=false] If freezeTableName is true, sequelize will not try to alter the DAO name to get the table name. Otherwise, the model name will be pluralized
* @param {Boolean} [options.freezeTableName=false] If freezeTableName is true, sequelize will not try to alter the model name to get the table name. Otherwise, the model name will be pluralized
* @param {Object} [options.name] An object with two attributes, `singular` and `plural`, which are used when this model is associated to others.
* @param {Object} [options.fieldMap] Map returned fields to arbitrary names for `SELECT` query type.
*
* @return {Promise}
* @memberof Sequelize
*
* @see {Model#build} for more information about instance option.
* @see {@link Model#build} for more information about instance option.
*/
query(sql,options){
if(arguments.length>2){
...
...
@@ -653,6 +653,7 @@ class Sequelize {
* @param {Object} options Query options.
* @param {Transaction} options.transaction The transaction that the query should be executed under
*
* @memberof Sequelize
* @return {Promise}
*/
set(variables,options){
...
...
@@ -693,10 +694,10 @@ class Sequelize {
/**
* Create a new database schema.
*
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* not a database table. In mysql and sqlite, this command will do nothing.
*
* @see {Model#schema}
* @see {@link Model#schema}
* @param {String} schema Name of the schema
* @param {Object} options={}
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
...
...
@@ -709,7 +710,7 @@ class Sequelize {
/**
* Show all defined schemas
*
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* not a database table. In mysql and sqlite, this will show all tables.
* @param {Object} options={}
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
...
...
@@ -722,7 +723,7 @@ class Sequelize {
/**
* Drop a single schema
*
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* not a database table. In mysql and sqlite, this drop a table matching the schema name
* @param {String} schema Name of the schema
* @param {Object} options={}
...
...
@@ -750,8 +751,8 @@ class Sequelize {
* Sync all defined models to the DB.
*
* @param {Object} [options={}]
* @param {Boolean} [options.force=false] If force is true, each DAO will do DROP TABLE IF EXISTS ..., before it tries to create its own table
* @param {RegEx} [options.match] Match a regex against the database name before syncing, a safety check for cases where force: true is used in tests but not live code
* @param {Boolean} [options.force=false] If force is true, each Model will run `DROP TABLE IF EXISTS`, before it tries to create its own table
* @param {RegExp} [options.match] Match a regex against the database name before syncing, a safety check for cases where force: true is used in tests but not live code
* @param {Boolean|function} [options.logging=console.log] A function that logs sql queries, or false for no logging
* @param {String} [options.schema='public'] The schema that the tables should be created in. This can be overriden for each table in sequelize.define
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
...
...
@@ -809,7 +810,7 @@ class Sequelize {
* @param {Boolean|function} [options.logging] A function that logs sql queries, or false for no logging
* @return {Promise}
*
* @see {Model#truncate} for more information
* @see {@link Model#truncate} for more information
*/
truncate(options){
constmodels=[];
...
...
@@ -831,7 +832,7 @@ class Sequelize {
/**
* Drop all tables defined through this sequelize instance. This is done by calling Model.drop on each model
* @see {Model#drop} for options
* @see {@link Model#drop} for options
*
* @param {object} options The options passed to each call to Model.drop
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
...
...
@@ -852,9 +853,7 @@ class Sequelize {
/**
* Test the connection by trying to authenticate
*
* @fires success If authentication was successful
* @error 'Invalid credentials' if the authentication failed (even if the database did not respond at all...)
* @alias validate
* @return {Promise}
*/
authenticate(options){
...
...
@@ -876,16 +875,17 @@ class Sequelize {
* })
* ```
*
* @see {Model#find}
* @see {Model#findAll}
* @see {Model#define}
* @see {Sequelize#col}
* @see {@link Model#find}
* @see {@link Model#findAll}
* @see {@link Model#define}
* @see {@link Sequelize#col}
* @method fn
*
* @param {String} fn The function you want to call
* @param {any} args All further arguments will be passed as arguments to the function
*
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.fn}
*/
staticfn(fn){
...
...
@@ -894,11 +894,12 @@ class Sequelize {
/**
* 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 {Sequelize#fn}
* @see {@link Sequelize#fn}
*
* @method col
* @param {String} col The name of the column
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.col}
*/
staticcol(col){
...
...
@@ -912,6 +913,7 @@ class Sequelize {
* @param {any} val The value to cast
* @param {String} type The type to cast it to
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.cast}
*/
staticcast(val,type){
...
...
@@ -925,6 +927,7 @@ class Sequelize {
* @param {any} val
* @alias asIs
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.literal}
*/
staticliteral(val){
...
...
@@ -933,11 +936,12 @@ class Sequelize {
/**
* An AND query
* @see {Model#find}
* @see {@link Model#find}
*
* @method and
* @param {String|Object} args Each argument will be joined by AND
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.and}
*/
staticand(){
...
...
@@ -946,11 +950,12 @@ class Sequelize {
/**
* An OR query
* @see {Model#find}
* @see {@link Model#find}
*
* @method or
* @param {String|Object} args Each argument will be joined by OR
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.or}
*/
staticor(){
...
...
@@ -959,11 +964,12 @@ class Sequelize {
/**
* Creates an object representing nested where conditions for postgres's json data-type.
* @see {Model#find}
* @see {@link Model#find}
*
* @method json
* @param {String|Object} conditions A hash containing strings/numbers or other nested hash, a string using dot notation or a string using postgres json syntax.
* @param {String|Number|Boolean} [value] An optional value to compare against. Produces a string of the form "<json path> = '<value>'".
* @memberof Sequelize
* @return {Sequelize.json}
*/
staticjson(conditionsOrPath,value){
...
...
@@ -978,7 +984,7 @@ class Sequelize {
*
* For string attributes, use the regular `{ where: { attr: something }}` syntax. If you don't want your string to be escaped, use `sequelize.literal`.
*
* @see {Model#find}
* @see {@link Model#find}
*
* @param {Object} attr The attribute, which can be either an attribute object from `Model.rawAttributes` or a sequelize object, for example an instance of `sequelize.fn`. For simple string attributes, use the POJO syntax
* @param {string} [comparator='=']
...
...
@@ -986,6 +992,7 @@ class Sequelize {
* @method where
* @alias condition
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.where}
*/
staticwhere(attr,comparator,logic){
...
...
@@ -1029,15 +1036,14 @@ class Sequelize {
* ```
* Note, that CLS is enabled for all sequelize instances, and all instances will share the same namespace
*
* @see {Transaction}
* @see {@link Transaction}
* @param {Object} [options={}]
* @param {Boolean} [options.autocommit]
* @param {String} [options.type='DEFERRED'] See `Sequelize.Transaction.TYPES` for possible options. Sqlite only.
* @param {String} [options.isolationLevel] See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Function} [autoCallback] The callback is called with the transaction object, and should return a promise. If the promise is resolved, the transaction commits; if the promise rejects, the transaction rolls back
* @return {Promise}
* @fires error If there is an uncaught error during the transaction
* @fires success When the transaction has ended (either committed or rolled back)
* 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.