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

Commit df3cb0c2 by Mick Hansen

Merge branch 'master' of github.com:sequelize/sequelize

2 parents c1da3af0 2c924949
...@@ -514,9 +514,9 @@ class BelongsToMany extends Association { ...@@ -514,9 +514,9 @@ class BelongsToMany extends Association {
if (instance instanceof association.target) { if (instance instanceof association.target) {
return instance.where(); return instance.where();
} else { } else {
const $where = {}; const where = {};
$where[association.target.primaryKeyAttribute] = instance; where[association.target.primaryKeyAttribute] = instance;
return $where; return where;
} }
}); });
......
...@@ -21,16 +21,16 @@ function addForeignKeyConstraints (newAttribute, source, target, options, key) { ...@@ -21,16 +21,16 @@ function addForeignKeyConstraints (newAttribute, source, target, options, key) {
// Find primary keys: composite keys not supported with this approach // Find primary keys: composite keys not supported with this approach
const primaryKeys = Utils._.chain(source.rawAttributes).keys() const primaryKeys = Utils._.chain(source.rawAttributes).keys()
.filter($key => source.rawAttributes[$key].primaryKey) .filter(key => source.rawAttributes[key].primaryKey)
.map($key => source.rawAttributes[$key].field || $key).value(); .map(key => source.rawAttributes[key].field || key).value();
if (primaryKeys.length === 1) { if (primaryKeys.length === 1) {
if (!!source.$schema) { if (!!source._schema) {
newAttribute.references = { newAttribute.references = {
model: source.modelManager.sequelize.queryInterface.QueryGenerator.addSchema({ model: source.modelManager.sequelize.queryInterface.QueryGenerator.addSchema({
tableName: source.tableName, tableName: source.tableName,
$schema: source.$schema, _schema: source._schema,
$schemaDelimiter: source.$schemaDelimiter _schemaDelimiter: source._schemaDelimiter
}) })
}; };
} else { } else {
......
...@@ -73,8 +73,8 @@ ABSTRACT.warn = function warn(link, text) { ...@@ -73,8 +73,8 @@ ABSTRACT.warn = function warn(link, text) {
} }
}; };
ABSTRACT.prototype.stringify = function stringify(value, options) { ABSTRACT.prototype.stringify = function stringify(value, options) {
if (this.$stringify) { if (this._stringify) {
return this.$stringify(value, options); return this._stringify(value, options);
} }
return value; return value;
}; };
...@@ -361,7 +361,7 @@ DECIMAL.prototype.validate = function validate(value) { ...@@ -361,7 +361,7 @@ DECIMAL.prototype.validate = function validate(value) {
for (const floating of [FLOAT, DOUBLE, REAL]) { for (const floating of [FLOAT, DOUBLE, REAL]) {
floating.prototype.escape = false; floating.prototype.escape = false;
floating.prototype.$stringify = function $stringify(value) { floating.prototype._stringify = function _stringify(value) {
if (isNaN(value)) { if (isNaN(value)) {
return "'NaN'"; return "'NaN'";
} else if (!isFinite(value)) { } else if (!isFinite(value)) {
...@@ -435,7 +435,7 @@ DATE.prototype.validate = function validate(value) { ...@@ -435,7 +435,7 @@ DATE.prototype.validate = function validate(value) {
return true; return true;
}; };
DATE.prototype.$applyTimezone = function $applyTimezone(date, options) { DATE.prototype._applyTimezone = function _applyTimezone(date, options) {
if (options.timezone) { if (options.timezone) {
if (momentTz.tz.zone(options.timezone)) { if (momentTz.tz.zone(options.timezone)) {
date = momentTz(date).tz(options.timezone); date = momentTz(date).tz(options.timezone);
...@@ -449,8 +449,8 @@ DATE.prototype.$applyTimezone = function $applyTimezone(date, options) { ...@@ -449,8 +449,8 @@ DATE.prototype.$applyTimezone = function $applyTimezone(date, options) {
return date; return date;
}; };
DATE.prototype.$stringify = function $stringify(date, options) { DATE.prototype._stringify = function _stringify(date, options) {
date = this.$applyTimezone(date, options); date = this._applyTimezone(date, options);
// Z here means current timezone, _not_ UTC // Z here means current timezone, _not_ UTC
return date.format('YYYY-MM-DD HH:mm:ss.SSS Z'); return date.format('YYYY-MM-DD HH:mm:ss.SSS Z');
...@@ -504,7 +504,7 @@ JSONTYPE.prototype.validate = function validate(value) { ...@@ -504,7 +504,7 @@ JSONTYPE.prototype.validate = function validate(value) {
return true; return true;
}; };
JSONTYPE.prototype.$stringify = function $stringify(value, options) { JSONTYPE.prototype._stringify = function _stringify(value, options) {
return JSON.stringify(value); return JSON.stringify(value);
}; };
...@@ -566,7 +566,7 @@ BLOB.prototype.validate = function validate(value) { ...@@ -566,7 +566,7 @@ BLOB.prototype.validate = function validate(value) {
}; };
BLOB.prototype.escape = false; BLOB.prototype.escape = false;
BLOB.prototype.$stringify = function $stringify(value) { BLOB.prototype._stringify = function _stringify(value) {
if (!Buffer.isBuffer(value)) { if (!Buffer.isBuffer(value)) {
if (Array.isArray(value)) { if (Array.isArray(value)) {
value = new Buffer(value); value = new Buffer(value);
...@@ -576,10 +576,10 @@ BLOB.prototype.$stringify = function $stringify(value) { ...@@ -576,10 +576,10 @@ BLOB.prototype.$stringify = function $stringify(value) {
} }
const hex = value.toString('hex'); const hex = value.toString('hex');
return this.$hexify(hex); return this._hexify(hex);
}; };
BLOB.prototype.$hexify = function $hexify(hex) { BLOB.prototype._hexify = function _hexify(hex) {
return "X'" + hex + "'"; return "X'" + hex + "'";
}; };
...@@ -882,7 +882,7 @@ inherits(GEOMETRY, ABSTRACT); ...@@ -882,7 +882,7 @@ inherits(GEOMETRY, ABSTRACT);
GEOMETRY.prototype.key = GEOMETRY.key = 'GEOMETRY'; GEOMETRY.prototype.key = GEOMETRY.key = 'GEOMETRY';
GEOMETRY.prototype.escape = false; GEOMETRY.prototype.escape = false;
GEOMETRY.prototype.$stringify = function $stringify(value) { GEOMETRY.prototype._stringify = function _stringify(value) {
return 'GeomFromText(\'' + Wkt.convert(value) + '\')'; return 'GeomFromText(\'' + Wkt.convert(value) + '\')';
}; };
...@@ -905,7 +905,7 @@ inherits(GEOGRAPHY, ABSTRACT); ...@@ -905,7 +905,7 @@ inherits(GEOGRAPHY, ABSTRACT);
GEOGRAPHY.prototype.key = GEOGRAPHY.key = 'GEOGRAPHY'; GEOGRAPHY.prototype.key = GEOGRAPHY.key = 'GEOGRAPHY';
GEOGRAPHY.prototype.escape = false; GEOGRAPHY.prototype.escape = false;
GEOGRAPHY.prototype.$stringify = function $stringify(value) { GEOGRAPHY.prototype._stringify = function _stringify(value) {
return 'GeomFromText(\'' + Wkt.convert(value) + '\')'; return 'GeomFromText(\'' + Wkt.convert(value) + '\')';
}; };
......
...@@ -26,7 +26,7 @@ class ConnectionManager { ...@@ -26,7 +26,7 @@ class ConnectionManager {
if (config.pool !== false) { if (config.pool !== false) {
config.pool =_.defaults(config.pool || {}, defaultPoolingConfig, { config.pool =_.defaults(config.pool || {}, defaultPoolingConfig, {
validate: this.$validate.bind(this) validate: this._validate.bind(this)
}) ; }) ;
} else { } else {
throw new Error('Support for pool:false was removed in v4.0'); throw new Error('Support for pool:false was removed in v4.0');
...@@ -42,7 +42,7 @@ class ConnectionManager { ...@@ -42,7 +42,7 @@ class ConnectionManager {
_.each(dataTypes, (dataType, key) => { _.each(dataTypes, (dataType, key) => {
if (dataType.hasOwnProperty('parse')) { if (dataType.hasOwnProperty('parse')) {
if (dataType.types[this.dialectName]) { if (dataType.types[this.dialectName]) {
this.$refreshTypeParser(dataType); this._refreshTypeParser(dataType);
} else { } else {
throw new Error('Parse function not supported for type ' + dataType.key + ' in dialect ' + this.dialectName); throw new Error('Parse function not supported for type ' + dataType.key + ' in dialect ' + this.dialectName);
} }
...@@ -77,14 +77,14 @@ class ConnectionManager { ...@@ -77,14 +77,14 @@ class ConnectionManager {
this.pool = Pooling.Pool({ this.pool = Pooling.Pool({
name: 'sequelize-connection', name: 'sequelize-connection',
create: (callback) => { create: (callback) => {
this.$connect(config).nodeify((err, connection) => { this._connect(config).nodeify((err, connection) => {
debug(`pool created max/min: ${config.pool.max}/${config.pool.min} with no replication`); debug(`pool created max/min: ${config.pool.max}/${config.pool.min} with no replication`);
callback(err, connection); // For some reason this is needed, else generic-pool things err is a connection or some shit callback(err, connection); // For some reason this is needed, else generic-pool things err is a connection or some shit
}); });
}, },
destroy: (connection) => { destroy: (connection) => {
debug(`connection destroy`); debug(`connection destroy`);
this.$disconnect(connection); this._disconnect(connection);
return null; return null;
}, },
max: config.pool.max, max: config.pool.max,
...@@ -145,14 +145,14 @@ class ConnectionManager { ...@@ -145,14 +145,14 @@ class ConnectionManager {
create: (callback) => { create: (callback) => {
// Simple round robin config // Simple round robin config
const nextRead = reads++ % config.replication.read.length; const nextRead = reads++ % config.replication.read.length;
this.$connect(config.replication.read[nextRead]).tap(connection => { this._connect(config.replication.read[nextRead]).tap(connection => {
connection.queryType = 'read'; connection.queryType = 'read';
}).nodeify((err, connection) => { }).nodeify((err, connection) => {
callback(err, connection); // For some reason this is needed, else generic-pool things err is a connection or some shit callback(err, connection); // For some reason this is needed, else generic-pool things err is a connection or some shit
}); });
}, },
destroy: connection => { destroy: connection => {
this.$disconnect(connection); this._disconnect(connection);
return null; return null;
}, },
validate: config.pool.validate, validate: config.pool.validate,
...@@ -163,14 +163,14 @@ class ConnectionManager { ...@@ -163,14 +163,14 @@ class ConnectionManager {
write: Pooling.Pool({ write: Pooling.Pool({
name: 'sequelize-connection-write', name: 'sequelize-connection-write',
create: callback => { create: callback => {
this.$connect(config.replication.write).tap(connection => { this._connect(config.replication.write).tap(connection => {
connection.queryType = 'write'; connection.queryType = 'write';
}).nodeify((err, connection) => { }).nodeify((err, connection) => {
callback(err, connection); // For some reason this is needed, else generic-pool things err is a connection or some shit callback(err, connection); // For some reason this is needed, else generic-pool things err is a connection or some shit
}); });
}, },
destroy: connection => { destroy: connection => {
this.$disconnect(connection); this._disconnect(connection);
return null; return null;
}, },
validate: config.pool.validate, validate: config.pool.validate,
...@@ -189,7 +189,7 @@ class ConnectionManager { ...@@ -189,7 +189,7 @@ class ConnectionManager {
if (this.versionPromise) { if (this.versionPromise) {
promise = this.versionPromise; promise = this.versionPromise;
} else { } else {
promise = this.versionPromise = this.$connect(this.config.replication.write || this.config).then(connection => { promise = this.versionPromise = this._connect(this.config.replication.write || this.config).then(connection => {
const _options = {}; const _options = {};
_options.transaction = {connection}; // Cheat .query to use our private connection _options.transaction = {connection}; // Cheat .query to use our private connection
_options.logging = () => {}; _options.logging = () => {};
...@@ -200,7 +200,7 @@ class ConnectionManager { ...@@ -200,7 +200,7 @@ class ConnectionManager {
this.versionPromise = null; this.versionPromise = null;
this.$disconnect(connection); this._disconnect(connection);
return null; return null;
}); });
}).catch(err => { }).catch(err => {
...@@ -229,16 +229,16 @@ class ConnectionManager { ...@@ -229,16 +229,16 @@ class ConnectionManager {
}); });
} }
$connect(config) { _connect(config) {
return this.sequelize.runHooks('beforeConnect', config) return this.sequelize.runHooks('beforeConnect', config)
.then(() => this.dialect.connectionManager.connect(config)); .then(() => this.dialect.connectionManager.connect(config));
} }
$disconnect(connection) { _disconnect(connection) {
return this.dialect.connectionManager.disconnect(connection); return this.dialect.connectionManager.disconnect(connection);
} }
$validate(connection) { _validate(connection) {
if (!this.dialect.connectionManager.validate) return Promise.resolve(); if (!this.dialect.connectionManager.validate) return Promise.resolve();
return this.dialect.connectionManager.validate(connection); return this.dialect.connectionManager.validate(connection);
} }
......
...@@ -32,14 +32,14 @@ const QueryGenerator = { ...@@ -32,14 +32,14 @@ const QueryGenerator = {
addSchema(param) { addSchema(param) {
const self = this; const self = this;
if (!param.$schema) return param.tableName || param; if (!param._schema) return param.tableName || param;
return { return {
tableName: param.tableName || param, tableName: param.tableName || param,
table: param.tableName || param, table: param.tableName || param,
name: param.name || param, name: param.name || param,
schema: param.$schema, schema: param._schema,
delimiter: param.$schemaDelimiter || '.', delimiter: param._schemaDelimiter || '.',
toString() { toString() {
return self.quoteTable(this); return self.quoteTable(this);
} }
...@@ -77,8 +77,8 @@ const QueryGenerator = { ...@@ -77,8 +77,8 @@ const QueryGenerator = {
const table = this.quoteTable( const table = this.quoteTable(
this.addSchema({ this.addSchema({
tableName, tableName,
$schema: schema, _schema: schema,
$schemaDelimiter: schemaDelimiter _schemaDelimiter: schemaDelimiter
}) })
); );
...@@ -633,7 +633,7 @@ const QueryGenerator = { ...@@ -633,7 +633,7 @@ const QueryGenerator = {
options = this.nameIndexes([options], options.prefix)[0]; options = this.nameIndexes([options], options.prefix)[0];
} }
options = Model.$conformIndex(options); options = Model._conformIndex(options);
if (!this._dialect.supports.index.type) { if (!this._dialect.supports.index.type) {
delete options.type; delete options.type;
...@@ -1109,7 +1109,7 @@ const QueryGenerator = { ...@@ -1109,7 +1109,7 @@ const QueryGenerator = {
} }
} }
attr = attr.map($attr => $attr._isSequelizeMethod ? this.handleSequelizeMethod($attr) : $attr); attr = attr.map(attr => attr._isSequelizeMethod ? this.handleSequelizeMethod(attr) : attr);
attrAs = attr[1]; attrAs = attr[1];
attr = attr[0]; attr = attr[0];
...@@ -1233,7 +1233,7 @@ const QueryGenerator = { ...@@ -1233,7 +1233,7 @@ const QueryGenerator = {
let parent = include; let parent = include;
let child = include; let child = include;
let nestedIncludes = []; let nestedIncludes = [];
let $query; let query;
while (parent = parent.parent) { while (parent = parent.parent) {
nestedIncludes = [_.extend({}, child, {include: nestedIncludes})]; nestedIncludes = [_.extend({}, child, {include: nestedIncludes})];
...@@ -1244,9 +1244,9 @@ const QueryGenerator = { ...@@ -1244,9 +1244,9 @@ const QueryGenerator = {
const topParent = topInclude.parent; const topParent = topInclude.parent;
if (topInclude.through && Object(topInclude.through.model) === topInclude.through.model) { if (topInclude.through && Object(topInclude.through.model) === topInclude.through.model) {
$query = this.selectQuery(topInclude.through.model.getTableName(), { query = this.selectQuery(topInclude.through.model.getTableName(), {
attributes: [topInclude.through.model.primaryKeyField], attributes: [topInclude.through.model.primaryKeyField],
include: Model.$validateIncludedElements({ include: Model._validateIncludedElements({
model: topInclude.through.model, model: topInclude.through.model,
include: [{ include: [{
association: topInclude.association.toTarget, association: topInclude.association.toTarget,
...@@ -1265,7 +1265,7 @@ const QueryGenerator = { ...@@ -1265,7 +1265,7 @@ const QueryGenerator = {
includeIgnoreAttributes: false includeIgnoreAttributes: false
}, topInclude.through.model); }, topInclude.through.model);
} else { } else {
$query = this.selectQuery(topInclude.model.tableName, { query = this.selectQuery(topInclude.model.tableName, {
attributes: [topInclude.model.primaryKeyAttributes[0]], attributes: [topInclude.model.primaryKeyAttributes[0]],
include: topInclude.include, include: topInclude.include,
where: { where: {
...@@ -1281,7 +1281,7 @@ const QueryGenerator = { ...@@ -1281,7 +1281,7 @@ const QueryGenerator = {
options.where['__' + throughAs] = this.sequelize.asIs([ options.where['__' + throughAs] = this.sequelize.asIs([
'(', '(',
$query.replace(/\;$/, ''), query.replace(/\;$/, ''),
')', ')',
'IS NOT NULL' 'IS NOT NULL'
].join(' ')); ].join(' '));
...@@ -2014,93 +2014,93 @@ const QueryGenerator = { ...@@ -2014,93 +2014,93 @@ const QueryGenerator = {
} }
if (_.isPlainObject(value) && fieldType instanceof DataTypes.JSON && options.json !== false) { if (_.isPlainObject(value) && fieldType instanceof DataTypes.JSON && options.json !== false) {
const $items = []; const items = [];
const traverse = (prop, item, path) => { const traverse = (prop, item, path) => {
const $where = {}; const where = {};
let $cast; let cast;
if (path[path.length - 1].indexOf('::') > -1) { if (path[path.length - 1].indexOf('::') > -1) {
const $tmp = path[path.length - 1].split('::'); const tmp = path[path.length - 1].split('::');
$cast = $tmp[1]; cast = tmp[1];
path[path.length - 1] = $tmp[0]; path[path.length - 1] = tmp[0];
} }
let $baseKey = this.quoteIdentifier(key)+'#>>\'{'+path.join(', ')+'}\''; let baseKey = this.quoteIdentifier(key)+'#>>\'{'+path.join(', ')+'}\'';
if (options.prefix) { if (options.prefix) {
if (options.prefix instanceof Utils.Literal) { if (options.prefix instanceof Utils.Literal) {
$baseKey = this.handleSequelizeMethod(options.prefix)+'.'+$baseKey; baseKey = this.handleSequelizeMethod(options.prefix)+'.'+baseKey;
} else { } else {
$baseKey = this.quoteTable(options.prefix)+'.'+$baseKey; baseKey = this.quoteTable(options.prefix)+'.'+baseKey;
} }
} }
$baseKey = '('+$baseKey+')'; baseKey = '('+baseKey+')';
const castKey = $item => { const castKey = item => {
let key = $baseKey; let key = baseKey;
if (!$cast) { if (!cast) {
if (typeof $item === 'number') { if (typeof item === 'number') {
$cast = 'double precision'; cast = 'double precision';
} else if ($item instanceof Date) { } else if (item instanceof Date) {
$cast = 'timestamptz'; cast = 'timestamptz';
} else if (typeof $item === 'boolean') { } else if (typeof item === 'boolean') {
$cast = 'boolean'; cast = 'boolean';
} }
} }
if ($cast) { if (cast) {
key += '::'+$cast; key += '::'+cast;
} }
return key; return key;
}; };
if (_.isPlainObject(item)) { if (_.isPlainObject(item)) {
_.forOwn(item, ($item, $prop) => { _.forOwn(item, (item, prop) => {
if ($prop.indexOf('$') === 0) { if (prop.indexOf('$') === 0) {
$where[$prop] = $item; where[prop] = item;
const $key = castKey($item); const key = castKey(item);
$items.push(this.whereItemQuery(new Utils.Literal($key), $where/*, _.pick(options, 'prefix')*/)); items.push(this.whereItemQuery(new Utils.Literal(key), where/*, _.pick(options, 'prefix')*/));
} else { } else {
traverse($prop, $item, path.concat([$prop])); traverse(prop, item, path.concat([prop]));
} }
}); });
} else { } else {
$where.$eq = item; where.$eq = item;
const $key = castKey(item); const key = castKey(item);
$items.push(this.whereItemQuery(new Utils.Literal($key), $where/*, _.pick(options, 'prefix')*/)); items.push(this.whereItemQuery(new Utils.Literal(key), where/*, _.pick(options, 'prefix')*/));
} }
}; };
_.forOwn(value, (item, prop) => { _.forOwn(value, (item, prop) => {
if (prop.indexOf('$') === 0) { if (prop.indexOf('$') === 0) {
const $where = {}; const where = {};
$where[prop] = item; where[prop] = item;
$items.push(this.whereItemQuery(key, $where, _.assign({}, options, {json: false}))); items.push(this.whereItemQuery(key, where, _.assign({}, options, {json: false})));
return; return;
} }
traverse(prop, item, [prop]); traverse(prop, item, [prop]);
}); });
const result = $items.join(' AND '); const result = items.join(' AND ');
return $items.length > 1 ? '('+result+')' : result; return items.length > 1 ? '('+result+')' : result;
} }
// If multiple keys we combine the different logic conditions // If multiple keys we combine the different logic conditions
if (_.isPlainObject(value) && Object.keys(value).length > 1) { if (_.isPlainObject(value) && Object.keys(value).length > 1) {
const $items = []; const items = [];
_.forOwn(value, (item, logic) => { _.forOwn(value, (item, logic) => {
const $where = {}; const where = {};
$where[logic] = item; where[logic] = item;
$items.push(this.whereItemQuery(key, $where, options)); items.push(this.whereItemQuery(key, where, options));
}); });
return '('+$items.join(' AND ')+')'; return '('+items.join(' AND ')+')';
} }
// Do [] to $in/$notIn normalization // Do [] to $in/$notIn normalization
......
...@@ -272,7 +272,7 @@ class AbstractQuery { ...@@ -272,7 +272,7 @@ class AbstractQuery {
}); });
// Queries with include // Queries with include
} else if (this.options.hasJoin === true) { } else if (this.options.hasJoin === true) {
results = AbstractQuery.$groupJoinData(results, { results = AbstractQuery._groupJoinData(results, {
model: this.model, model: this.model,
includeMap: this.options.includeMap, includeMap: this.options.includeMap,
includeNames: this.options.includeNames includeNames: this.options.includeNames
...@@ -354,7 +354,7 @@ class AbstractQuery { ...@@ -354,7 +354,7 @@ class AbstractQuery {
* } * }
* ] * ]
*/ */
static $groupJoinData(rows, includeOptions, options) { static _groupJoinData(rows, includeOptions, options) {
/* /*
* Assumptions * Assumptions
......
...@@ -26,11 +26,11 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -26,11 +26,11 @@ class ConnectionManager extends AbstractConnectionManager {
} }
// Expose this as a method so that the parsing may be updated when the user has added additional, custom types // Expose this as a method so that the parsing may be updated when the user has added additional, custom types
$refreshTypeParser(dataType) { _refreshTypeParser(dataType) {
parserStore.refresh(dataType); parserStore.refresh(dataType);
} }
$clearTypeParser() { _clearTypeParser() {
parserStore.clear(); parserStore.clear();
} }
......
...@@ -42,7 +42,7 @@ module.exports = BaseTypes => { ...@@ -42,7 +42,7 @@ module.exports = BaseTypes => {
return 'VARBINARY(MAX)'; return 'VARBINARY(MAX)';
}; };
BLOB.prototype.$hexify = function $hexify(hex) { BLOB.prototype._hexify = function _hexify(hex) {
return '0x' + hex; return '0x' + hex;
}; };
...@@ -61,9 +61,9 @@ module.exports = BaseTypes => { ...@@ -61,9 +61,9 @@ module.exports = BaseTypes => {
}; };
STRING.prototype.escape = false; STRING.prototype.escape = false;
STRING.prototype.$stringify = function $stringify(value, options) { STRING.prototype._stringify = function _stringify(value, options) {
if (this._binary) { if (this._binary) {
return BLOB.prototype.$stringify(value); return BLOB.prototype._stringify(value);
} else { } else {
return options.escape(value); return options.escape(value);
} }
...@@ -128,8 +128,8 @@ module.exports = BaseTypes => { ...@@ -128,8 +128,8 @@ module.exports = BaseTypes => {
return 'DATETIME2'; return 'DATETIME2';
}; };
DATE.prototype.$stringify = function $stringify(date, options) { DATE.prototype._stringify = function _stringify(date, options) {
date = this.$applyTimezone(date, options); date = this._applyTimezone(date, options);
// mssql not allow +timezone datetime format // mssql not allow +timezone datetime format
return date.format('YYYY-MM-DD HH:mm:ss.SSS'); return date.format('YYYY-MM-DD HH:mm:ss.SSS');
......
...@@ -12,6 +12,8 @@ var throwMethodUndefined = function(methodName) { ...@@ -12,6 +12,8 @@ var throwMethodUndefined = function(methodName) {
}; };
var QueryGenerator = { var QueryGenerator = {
/* jshint proto:true */
__proto__: AbstractQueryGenerator,
options: {}, options: {},
dialect: 'mssql', dialect: 'mssql',
...@@ -710,4 +712,4 @@ function wrapSingleQuote(identifier){ ...@@ -710,4 +712,4 @@ function wrapSingleQuote(identifier){
return Utils.addTicks(identifier, "'"); return Utils.addTicks(identifier, "'");
} }
module.exports = Utils._.extend(Utils._.clone(AbstractQueryGenerator), QueryGenerator); module.exports = QueryGenerator;
...@@ -31,17 +31,17 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -31,17 +31,17 @@ class ConnectionManager extends AbstractConnectionManager {
} }
// Expose this as a method so that the parsing may be updated when the user has added additional, custom types // Expose this as a method so that the parsing may be updated when the user has added additional, custom types
$refreshTypeParser(dataType) { _refreshTypeParser(dataType) {
for (const type of dataType.types.mysql) { for (const type of dataType.types.mysql) {
parserMap.set(type, dataType.parse); parserMap.set(type, dataType.parse);
} }
} }
$clearTypeParser() { _clearTypeParser() {
parserMap.clear(); parserMap.clear();
} }
static $typecast(field, next) { static _typecast(field, next) {
if (parserMap.has(field.type)) { if (parserMap.has(field.type)) {
return parserMap.get(field.type)(field, this.sequelize.options); return parserMap.get(field.type)(field, this.sequelize.options);
} }
...@@ -58,7 +58,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -58,7 +58,7 @@ class ConnectionManager extends AbstractConnectionManager {
password: config.password, password: config.password,
database: config.database, database: config.database,
timezone: this.sequelize.options.timezone, timezone: this.sequelize.options.timezone,
typeCast: ConnectionManager.$typecast.bind(this), typeCast: ConnectionManager._typecast.bind(this),
bigNumberStrings: false, bigNumberStrings: false,
supportBigNumbers: true supportBigNumbers: true
}; };
......
...@@ -35,8 +35,8 @@ module.exports = BaseTypes => { ...@@ -35,8 +35,8 @@ module.exports = BaseTypes => {
return 'DATETIME' + (this._length ? '(' + this._length + ')' : ''); return 'DATETIME' + (this._length ? '(' + this._length + ')' : '');
}; };
DATE.prototype.$stringify = function $stringify(date, options) { DATE.prototype._stringify = function _stringify(date, options) {
date = BaseTypes.DATE.prototype.$applyTimezone(date, options); date = BaseTypes.DATE.prototype._applyTimezone(date, options);
// Fractional DATETIMEs only supported on MySQL 5.6.4+ // Fractional DATETIMEs only supported on MySQL 5.6.4+
if (this._length) { if (this._length) {
return date.format('YYYY-MM-DD HH:mm:ss.SSS'); return date.format('YYYY-MM-DD HH:mm:ss.SSS');
......
'use strict'; 'use strict';
const Utils = require('../../utils'); const Utils = require('../../utils');
const AbstractQueryGenerator = require('../abstract/query-generator');
const QueryGenerator = { const QueryGenerator = {
/* jshint proto:true */
__proto__: AbstractQueryGenerator,
dialect: 'mysql', dialect: 'mysql',
createSchema() { createSchema() {
...@@ -343,4 +346,4 @@ function wrapSingleQuote(identifier){ ...@@ -343,4 +346,4 @@ function wrapSingleQuote(identifier){
return Utils.addTicks(identifier, '\''); return Utils.addTicks(identifier, '\'');
} }
module.exports = Utils._.extend(Utils._.clone(require('../abstract/query-generator')), QueryGenerator); module.exports = QueryGenerator;
...@@ -34,7 +34,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -34,7 +34,7 @@ class ConnectionManager extends AbstractConnectionManager {
} }
// Expose this as a method so that the parsing may be updated when the user has added additional, custom types // Expose this as a method so that the parsing may be updated when the user has added additional, custom types
$refreshTypeParser(dataType) { _refreshTypeParser(dataType) {
if (dataType.types.postgres.oids) { if (dataType.types.postgres.oids) {
for (const oid of dataType.types.postgres.oids) { for (const oid of dataType.types.postgres.oids) {
...@@ -165,7 +165,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -165,7 +165,7 @@ class ConnectionManager extends AbstractConnectionManager {
type.types.postgres.oids.push(row.oid); type.types.postgres.oids.push(row.oid);
type.types.postgres.array_oids.push(row.typarray); type.types.postgres.array_oids.push(row.typarray);
this.$refreshTypeParser(type); this._refreshTypeParser(type);
}) })
.on('end', () => resolve()); .on('end', () => resolve());
}); });
......
...@@ -263,7 +263,7 @@ module.exports = BaseTypes => { ...@@ -263,7 +263,7 @@ module.exports = BaseTypes => {
return 'BYTEA'; return 'BYTEA';
}; };
BLOB.prototype.$hexify = function $hexify(hex) { BLOB.prototype._hexify = function _hexify(hex) {
// bytea hex format http://www.postgresql.org/docs/current/static/datatype-binary.html // bytea hex format http://www.postgresql.org/docs/current/static/datatype-binary.html
return "E'\\\\x" + hex + "'"; return "E'\\\\x" + hex + "'";
}; };
...@@ -305,7 +305,7 @@ module.exports = BaseTypes => { ...@@ -305,7 +305,7 @@ module.exports = BaseTypes => {
return wkx.Geometry.parse(b).toGeoJSON(); return wkx.Geometry.parse(b).toGeoJSON();
}; };
GEOMETRY.prototype.$stringify = function $stringify(value) { GEOMETRY.prototype._stringify = function _stringify(value) {
return 'ST_GeomFromGeoJSON(\'' + JSON.stringify(value) + '\')'; return 'ST_GeomFromGeoJSON(\'' + JSON.stringify(value) + '\')';
}; };
...@@ -341,7 +341,7 @@ module.exports = BaseTypes => { ...@@ -341,7 +341,7 @@ module.exports = BaseTypes => {
return wkx.Geometry.parse(b).toGeoJSON(); return wkx.Geometry.parse(b).toGeoJSON();
}; };
GEOGRAPHY.prototype.$stringify = function $stringify(value) { GEOGRAPHY.prototype._stringify = function _stringify(value) {
return 'ST_GeomFromGeoJSON(\'' + JSON.stringify(value) + '\')'; return 'ST_GeomFromGeoJSON(\'' + JSON.stringify(value) + '\')';
}; };
...@@ -366,7 +366,7 @@ module.exports = BaseTypes => { ...@@ -366,7 +366,7 @@ module.exports = BaseTypes => {
}; };
HSTORE.prototype.escape = false; HSTORE.prototype.escape = false;
HSTORE.prototype.$stringify = function $stringify(value) { HSTORE.prototype._stringify = function _stringify(value) {
if (!hstore) { if (!hstore) {
// All datatype files are loaded at import - make sure we don't load the hstore parser before a hstore is instantiated // All datatype files are loaded at import - make sure we don't load the hstore parser before a hstore is instantiated
hstore = require('./hstore'); hstore = require('./hstore');
...@@ -408,7 +408,7 @@ module.exports = BaseTypes => { ...@@ -408,7 +408,7 @@ module.exports = BaseTypes => {
}; };
RANGE.prototype.escape = false; RANGE.prototype.escape = false;
RANGE.prototype.$stringify = function $stringify(values, options) { RANGE.prototype._stringify = function _stringify(values, options) {
if (!Array.isArray(values)) { if (!Array.isArray(values)) {
return "'" + this.options.subtype.stringify(values, options) + "'::" + return "'" + this.options.subtype.stringify(values, options) + "'::" +
this.toCastType(); this.toCastType();
...@@ -433,7 +433,7 @@ module.exports = BaseTypes => { ...@@ -433,7 +433,7 @@ module.exports = BaseTypes => {
}; };
BaseTypes.ARRAY.prototype.escape = false; BaseTypes.ARRAY.prototype.escape = false;
BaseTypes.ARRAY.prototype.$stringify = function $stringify(values, options) { BaseTypes.ARRAY.prototype._stringify = function _stringify(values, options) {
let str = 'ARRAY[' + values.map(value => { let str = 'ARRAY[' + values.map(value => {
if (this.type && this.type.stringify) { if (this.type && this.type.stringify) {
value = this.type.stringify(value, options); value = this.type.stringify(value, options);
......
...@@ -9,6 +9,8 @@ const semver = require('semver'); ...@@ -9,6 +9,8 @@ const semver = require('semver');
const _ = require('lodash'); const _ = require('lodash');
const QueryGenerator = { const QueryGenerator = {
/* jshint proto:true */
__proto__: AbstractQueryGenerator,
options: {}, options: {},
dialect: 'postgres', dialect: 'postgres',
...@@ -801,4 +803,4 @@ const QueryGenerator = { ...@@ -801,4 +803,4 @@ const QueryGenerator = {
} }
}; };
module.exports = Utils._.extend(Utils._.clone(AbstractQueryGenerator), QueryGenerator); module.exports = QueryGenerator;
...@@ -33,11 +33,11 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -33,11 +33,11 @@ class ConnectionManager extends AbstractConnectionManager {
} }
// Expose this as a method so that the parsing may be updated when the user has added additional, custom types // Expose this as a method so that the parsing may be updated when the user has added additional, custom types
$refreshTypeParser(dataType) { _refreshTypeParser(dataType) {
parserStore.refresh(dataType); parserStore.refresh(dataType);
} }
$clearTypeParser() { _clearTypeParser() {
parserStore.clear(); parserStore.clear();
} }
......
...@@ -4,13 +4,11 @@ ...@@ -4,13 +4,11 @@
const Utils = require('../../utils'); const Utils = require('../../utils');
const Transaction = require('../../transaction'); const Transaction = require('../../transaction');
const _ = require('lodash'); const _ = require('lodash');
const MySqlQueryGenerator = require('../mysql/query-generator');
const MySqlQueryGenerator = Utils._.extend(
Utils._.clone(require('../abstract/query-generator')),
Utils._.clone(require('../mysql/query-generator'))
);
const QueryGenerator = { const QueryGenerator = {
/* jshint proto:true */
__proto__: MySqlQueryGenerator,
options: {}, options: {},
dialect: 'sqlite', dialect: 'sqlite',
...@@ -237,8 +235,8 @@ const QueryGenerator = { ...@@ -237,8 +235,8 @@ const QueryGenerator = {
describeTableQuery(tableName, schema, schemaDelimiter) { describeTableQuery(tableName, schema, schemaDelimiter) {
const table = { const table = {
$schema: schema, _schema: schema,
$schemaDelimiter: schemaDelimiter, _schemaDelimiter: schemaDelimiter,
tableName tableName
}; };
return `PRAGMA TABLE_INFO(${this.quoteTable(this.addSchema(table))});`; return `PRAGMA TABLE_INFO(${this.quoteTable(this.addSchema(table))});`;
...@@ -349,4 +347,4 @@ const QueryGenerator = { ...@@ -349,4 +347,4 @@ const QueryGenerator = {
} }
}; };
module.exports = Utils._.extend({}, MySqlQueryGenerator, QueryGenerator); module.exports = QueryGenerator;
...@@ -53,7 +53,7 @@ class Query extends AbstractQuery { ...@@ -53,7 +53,7 @@ class Query extends AbstractQuery {
return [sql, bindParam]; return [sql, bindParam];
} }
$collectModels(include, prefix) { _collectModels(include, prefix) {
const ret = {}; const ret = {};
if (include) { if (include) {
...@@ -67,7 +67,7 @@ class Query extends AbstractQuery { ...@@ -67,7 +67,7 @@ class Query extends AbstractQuery {
ret[key] = _include.model; ret[key] = _include.model;
if (_include.include) { if (_include.include) {
_.merge(ret, this.$collectModels(_include.include, key)); _.merge(ret, this._collectModels(_include.include, key));
} }
} }
} }
...@@ -136,7 +136,7 @@ class Query extends AbstractQuery { ...@@ -136,7 +136,7 @@ class Query extends AbstractQuery {
} else if (query.isSelectQuery()) { } else if (query.isSelectQuery()) {
if (!query.options.raw) { if (!query.options.raw) {
// This is a map of prefix strings to models, e.g. user.projects -> Project model // This is a map of prefix strings to models, e.g. user.projects -> Project model
const prefixes = query.$collectModels(query.options.include); const prefixes = query._collectModels(query.options.include);
results = results.map(result => { results = results.map(result => {
return _.mapValues(result, (value, name) => { return _.mapValues(result, (value, name) => {
......
...@@ -137,7 +137,7 @@ exports.DatabaseError = DatabaseError; ...@@ -137,7 +137,7 @@ exports.DatabaseError = DatabaseError;
* @extends DatabaseError * @extends DatabaseError
* @constructor * @constructor
*/ */
class TimeoutError extends BaseError { class TimeoutError extends DatabaseError {
constructor(parent) { constructor(parent) {
super(parent); super(parent);
this.name = 'SequelizeTimeoutError'; this.name = 'SequelizeTimeoutError';
......
'use strict'; 'use strict';
const Utils = require('./utils') const Utils = require('./utils');
, Promise = require('./promise') const Promise = require('./promise');
, debug = Utils.getLogger().debugContext('hooks'); const debug = Utils.getLogger().debugContext('hooks');
/** /**
* Hooks are function that are called before and after (bulk-) creation/updating/deletion and validation. Hooks can be added to you models in three ways: * Hooks are function that are called before and after (bulk-) creation/updating/deletion and validation. Hooks can be added to you models in three ways:
...@@ -14,11 +14,11 @@ const Utils = require('./utils') ...@@ -14,11 +14,11 @@ const Utils = require('./utils')
* // Method 1 * // Method 1
* sequelize.define(name, { attributes }, { * sequelize.define(name, { attributes }, {
* hooks: { * hooks: {
* beforeBulkCreate: function () { * beforeBulkCreate() {
* // can be a single function * // can be a single function
* }, * },
* beforeValidate: [ * beforeValidate: [
* function () {}, * function() {},
* function() {} // Or an array of several * function() {} // Or an array of several
* ] * ]
* } * }
...@@ -75,6 +75,7 @@ const hookTypes = { ...@@ -75,6 +75,7 @@ const hookTypes = {
beforeBulkSync: {params: 1}, beforeBulkSync: {params: 1},
afterBulkSync: {params: 1} afterBulkSync: {params: 1}
}; };
exports.hooks = hookTypes;
const hookAliases = { const hookAliases = {
beforeDelete: 'beforeDestroy', beforeDelete: 'beforeDestroy',
...@@ -83,6 +84,7 @@ const hookAliases = { ...@@ -83,6 +84,7 @@ const hookAliases = {
afterBulkDelete: 'afterBulkDestroy', afterBulkDelete: 'afterBulkDestroy',
beforeConnection: 'beforeConnect' beforeConnection: 'beforeConnect'
}; };
exports.hookAliases = hookAliases;
/** /**
* get array of current hook and its proxied hooks combined * get array of current hook and its proxied hooks combined
...@@ -94,10 +96,10 @@ const getProxiedHooks = (hookType) => ( ...@@ -94,10 +96,10 @@ const getProxiedHooks = (hookType) => (
); );
const Hooks = { const Hooks = {
replaceHookAliases: function(hooks) { replaceHookAliases(hooks) {
var realHookName; let realHookName;
Utils._.each(hooks, function(hooksArray, name) { Utils._.each(hooks, (hooksArray, name) => {
// Does an alias for this hook name exist? // Does an alias for this hook name exist?
if (realHookName = hookAliases[name]) { if (realHookName = hookAliases[name]) {
// Add the hooks to the actual hook // Add the hooks to the actual hook
...@@ -111,10 +113,9 @@ const Hooks = { ...@@ -111,10 +113,9 @@ const Hooks = {
return hooks; return hooks;
}, },
runHooks: function(hooks) { runHooks(hooks) {
var self = this const fnArgs = Utils.sliceArgs(arguments, 1);
, fnArgs = Utils.sliceArgs(arguments, 1) let hookType;
, hookType;
if (typeof hooks === 'string') { if (typeof hooks === 'string') {
hookType = hooks; hookType = hooks;
...@@ -129,34 +130,33 @@ const Hooks = { ...@@ -129,34 +130,33 @@ const Hooks = {
// run hooks as sync functions if flagged as sync // run hooks as sync functions if flagged as sync
if (hookTypes[hookType] && hookTypes[hookType].sync) { if (hookTypes[hookType] && hookTypes[hookType].sync) {
hooks.forEach(function(hook) { for (let hook of hooks) {
if (typeof hook === 'object') hook = hook.fn; if (typeof hook === 'object') hook = hook.fn;
debug(`running hook(sync) ${hookType}`); // log sync hooks debug(`running hook(sync) ${hookType}`); // log sync hooks
hook.apply(self, fnArgs); return hook.apply(this, fnArgs);
}); }
return; return;
} }
// run hooks async // run hooks async
var promise = Promise.each(hooks, function (hook) { const promise = Promise.each(hooks, hook => {
if (typeof hook === 'object') { if (typeof hook === 'object') {
hook = hook.fn; hook = hook.fn;
} }
if (hookType && hook.length > hookTypes[hookType].params) { if (hookType && hook.length > hookTypes[hookType].params) {
hook = Promise.promisify(hook, self); hook = Promise.promisify(hook, this);
} }
debug(`running hook ${hookType}`); // log async hook debug(`running hook ${hookType}`); // log async hook
return hook.apply(self, fnArgs); return hook.apply(this, fnArgs);
}) }).return();
.return();
return promise; return promise;
}, },
hook: function() { hook() {
return Hooks.addHook.apply(this, arguments); return Hooks.addHook.apply(this, arguments);
}, },
...@@ -169,7 +169,7 @@ const Hooks = { ...@@ -169,7 +169,7 @@ const Hooks = {
* *
* @alias hook * @alias hook
*/ */
addHook: function(hookType, name, fn) { addHook(hookType, name, fn) {
if (typeof name === 'function') { if (typeof name === 'function') {
fn = name; fn = name;
name = null; name = null;
...@@ -183,7 +183,7 @@ const Hooks = { ...@@ -183,7 +183,7 @@ const Hooks = {
Utils._.each(hookType, (type) => { Utils._.each(hookType, (type) => {
this.options.hooks[type] = this.options.hooks[type] || []; this.options.hooks[type] = this.options.hooks[type] || [];
this.options.hooks[type].push(!!name ? {name: name, fn: fn} : fn); this.options.hooks[type].push(!!name ? {name, fn} : fn);
}); });
return this; return this;
...@@ -195,9 +195,9 @@ const Hooks = { ...@@ -195,9 +195,9 @@ const Hooks = {
* @param {String} hookType * @param {String} hookType
* @param {String|Function} name * @param {String|Function} name
*/ */
removeHook: function(hookType, name) { removeHook(hookType, name) {
hookType = hookAliases[hookType] || hookType; hookType = hookAliases[hookType] || hookType;
let isReference = typeof name === 'function' ? true : false; const isReference = typeof name === 'function' ? true : false;
if (!this.hasHook(hookType)) { if (!this.hasHook(hookType)) {
return this; return this;
...@@ -208,15 +208,15 @@ const Hooks = { ...@@ -208,15 +208,15 @@ const Hooks = {
// check for proxies, add them too // check for proxies, add them too
hookType = getProxiedHooks(hookType); hookType = getProxiedHooks(hookType);
Utils._.each(hookType, (type) => { for (const type of hookType) {
this.options.hooks[type] = this.options.hooks[type].filter(function (hook) { this.options.hooks[type] = this.options.hooks[type].filter(hook => {
if (isReference && typeof hook === 'function') { if (isReference && typeof hook === 'function') {
return hook !== name; // check if same method return hook !== name; // check if same method
} else { } else {
return typeof hook === 'object' && hook.name !== name; return typeof hook === 'object' && hook.name !== name;
} }
}); });
}); }
return this; return this;
}, },
...@@ -228,13 +228,25 @@ const Hooks = { ...@@ -228,13 +228,25 @@ const Hooks = {
* *
* @alias hasHooks * @alias hasHooks
*/ */
hasHook: function(hookType) { hasHook(hookType) {
return this.options.hooks[hookType] && !!this.options.hooks[hookType].length; return this.options.hooks[hookType] && !!this.options.hooks[hookType].length;
}, },
}; };
Hooks.hasHooks = Hooks.hasHook; Hooks.hasHooks = Hooks.hasHook;
function applyTo(target) {
Utils._.mixin(target, Hooks);
const allHooks = Object.keys(hookTypes).concat(Object.keys(hookAliases));
for (const hook of allHooks) {
target[hook] = function(name, callback) {
return this.addHook(hook, name, callback);
};
}
}
exports.applyTo = applyTo;
/** /**
* A hook that is run before validation * A hook that is run before validation
* @param {String} name * @param {String} name
...@@ -472,54 +484,37 @@ Hooks.hasHooks = Hooks.hasHook; ...@@ -472,54 +484,37 @@ Hooks.hasHooks = Hooks.hasHook;
* @name afterInit * @name afterInit
*/ */
/** /**
* A hook that is run before a connection is created * A hook that is run before a connection is created
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with config passed to connection * @param {Function} fn A callback function that is called with config passed to connection
* @name beforeConnect * @name beforeConnect
*/ */
/**
* A hook that is run before Model.sync call
* @param {String} name
* @param {Function} fn A callback function that is called with options passed to Model.sync
* @name beforeSync
*/
/**
* A hook that is run after Model.sync call
* @param {String} name
* @param {Function} fn A callback function that is called with options passed to Model.sync
* @name afterSync
*/
/** /**
* A hook that is run before Model.sync call * A hook that is run before sequelize.sync call
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options passed to Model.sync * @param {Function} fn A callback function that is called with options passed to sequelize.sync
* @name beforeSync * @name beforeBulkSync
*/ */
/** /**
* A hook that is run after Model.sync call * A hook that is run after sequelize.sync call
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options passed to Model.sync * @param {Function} fn A callback function that is called with options passed to sequelize.sync
* @name afterSync * @name afterBulkSync
*/ */
/**
* A hook that is run before sequelize.sync call
* @param {String} name
* @param {Function} fn A callback function that is called with options passed to sequelize.sync
* @name beforeBulkSync
*/
/**
* A hook that is run after sequelize.sync call
* @param {String} name
* @param {Function} fn A callback function that is called with options passed to sequelize.sync
* @name afterBulkSync
*/
module.exports = {
hooks: hookTypes,
hookAliases: hookAliases,
applyTo: function(Model) {
Utils._.mixin(Model, Hooks);
Utils._.mixin(Model.prototype, Hooks);
var allHooks = Object.keys(hookTypes).concat(Object.keys(hookAliases));
allHooks.forEach(function(hook) {
Model[hook] = Model.prototype[hook] = function(name, callback) {
return this.addHook(hook, name, callback);
};
});
}
};
...@@ -133,7 +133,7 @@ class InstanceValidator { ...@@ -133,7 +133,7 @@ class InstanceValidator {
*/ */
_customValidators() { _customValidators() {
const validators = []; const validators = [];
Utils._.each(this.modelInstance.$modelOptions.validate, (validator, validatorType) => { Utils._.each(this.modelInstance._modelOptions.validate, (validator, validatorType) => {
if (this.options.skip.indexOf(validatorType) >= 0) { if (this.options.skip.indexOf(validatorType) >= 0) {
return; return;
} }
......
...@@ -16,10 +16,10 @@ class ModelManager { ...@@ -16,10 +16,10 @@ class ModelManager {
return model; return model;
} }
removeModel(model) { removeModel(modelToRemove) {
this.models = this.models.filter($model => $model.name !== model.name); this.models = this.models.filter(model => model.name !== modelToRemove.name);
delete this.sequelize.models[model.name]; delete this.sequelize.models[modelToRemove.name];
} }
getModel(against, options) { getModel(against, options) {
......
...@@ -135,10 +135,10 @@ class QueryInterface { ...@@ -135,10 +135,10 @@ class QueryInterface {
} }
if (!tableName.schema && if (!tableName.schema &&
(options.schema || (!!model && model.$schema))) { (options.schema || (!!model && model._schema))) {
tableName = this.QueryGenerator.addSchema({ tableName = this.QueryGenerator.addSchema({
tableName, tableName,
$schema: (!!model && model.$schema) || options.schema _schema: (!!model && model._schema) || options.schema
}); });
} }
...@@ -153,10 +153,10 @@ class QueryInterface { ...@@ -153,10 +153,10 @@ class QueryInterface {
}); });
} else { } else {
if (!tableName.schema && if (!tableName.schema &&
(options.schema || (!!model && model.$schema))) { (options.schema || (!!model && model._schema))) {
tableName = this.QueryGenerator.addSchema({ tableName = this.QueryGenerator.addSchema({
tableName, tableName,
$schema: (!!model && model.$schema) || options.schema _schema: (!!model && model._schema) || options.schema
}); });
} }
...@@ -541,7 +541,7 @@ class QueryInterface { ...@@ -541,7 +541,7 @@ class QueryInterface {
update(instance, tableName, values, identifier, options) { update(instance, tableName, values, identifier, options) {
options = _.clone(options || {}); options = _.clone(options || {});
options.hasTrigger = !!(instance && instance.$modelOptions && instance.$modelOptions.hasTrigger); options.hasTrigger = !!(instance && instance._modelOptions && instance._modelOptions.hasTrigger);
const sql = this.QueryGenerator.updateQuery(tableName, values, identifier, options, instance.constructor.rawAttributes); const sql = this.QueryGenerator.updateQuery(tableName, values, identifier, options, instance.constructor.rawAttributes);
...@@ -650,7 +650,7 @@ class QueryInterface { ...@@ -650,7 +650,7 @@ class QueryInterface {
if (options.schema) { if (options.schema) {
tableName = this.QueryGenerator.addSchema({ tableName = this.QueryGenerator.addSchema({
tableName, tableName,
$schema: options.schema _schema: options.schema
}); });
} }
......
...@@ -248,13 +248,13 @@ class Sequelize { ...@@ -248,13 +248,13 @@ class Sequelize {
this.importCache = {}; this.importCache = {};
this.test = { this.test = {
$trackRunningQueries: false, _trackRunningQueries: false,
$runningQueries: 0, _runningQueries: 0,
trackRunningQueries() { trackRunningQueries() {
this.$trackRunningQueries = true; this._trackRunningQueries = true;
}, },
verifyNoRunningQueries() { verifyNoRunningQueries() {
if (this.$runningQueries > 0) throw new Error('Expected 0 running queries. '+this.$runningQueries+' queries still running'); if (this._runningQueries > 0) throw new Error('Expected 0 running queries. '+this._runningQueries+' queries still running');
} }
}; };
...@@ -509,7 +509,7 @@ class Sequelize { ...@@ -509,7 +509,7 @@ class Sequelize {
* @param {Boolean} [options.nest=false] If true, transforms objects with `.` separated property names into nested objects using [dottie.js](https://github.com/mickhansen/dottie.js). For example { 'user.username': 'john' } becomes { user: { username: 'john' }}. When `nest` is true, the query type is assumed to be `'SELECT'`, unless otherwise specified * @param {Boolean} [options.nest=false] If true, transforms objects with `.` separated property names into nested objects using [dottie.js](https://github.com/mickhansen/dottie.js). For example { 'user.username': 'john' } becomes { user: { username: 'john' }}. When `nest` is true, the query type is assumed to be `'SELECT'`, unless otherwise specified
* @param {Boolean} [options.plain=false] Sets the query type to `SELECT` and return a single row * @param {Boolean} [options.plain=false] Sets the query type to `SELECT` and return a single row
* @param {Object|Array} [options.replacements] Either an object of named parameter replacements in the format `:param` or an array of unnamed replacements to replace `?` in your SQL. * @param {Object|Array} [options.replacements] Either an object of named parameter replacements in the format `:param` or an array of unnamed replacements to replace `?` in your SQL.
* @param {Object|Array} [options.bind] Either an object of named bind parameter in the format `$param` or an array of unnamed bind parameter to replace `$1, $2, ...` in your SQL. * @param {Object|Array} [options.bind] Either an object of named bind parameter in the format `_param` or an array of unnamed bind parameter to replace `$1, $2, ...` in your SQL.
* @param {Boolean} [options.useMaster=false] Force the query to use the write pool, regardless of the query type. * @param {Boolean} [options.useMaster=false] Force the query to use the write pool, regardless of the query type.
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql. * @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Instance} [options.instance] A sequelize instance used to build the return instance * @param {Instance} [options.instance] A sequelize instance used to build the return instance
...@@ -612,8 +612,8 @@ class Sequelize { ...@@ -612,8 +612,8 @@ class Sequelize {
return Promise.reject(error); return Promise.reject(error);
} }
if (this.test.$trackRunningQueries) { if (this.test._trackRunningQueries) {
this.test.$runningQueries++; this.test._runningQueries++;
} }
//if dialect doesn't support search_path or dialect option //if dialect doesn't support search_path or dialect option
...@@ -638,8 +638,8 @@ class Sequelize { ...@@ -638,8 +638,8 @@ class Sequelize {
} }
}), Utils._.extend(this.options.retry, options.retry || {})); }), Utils._.extend(this.options.retry, options.retry || {}));
}).finally(() => { }).finally(() => {
if (this.test.$trackRunningQueries) { if (this.test._trackRunningQueries) {
this.test.$runningQueries--; this.test._runningQueries--;
} }
}); });
} }
...@@ -1261,6 +1261,7 @@ Sequelize.useInflection = Utils.useInflection; ...@@ -1261,6 +1261,7 @@ Sequelize.useInflection = Utils.useInflection;
* and on Sequelize/sequelize methods e.g. Sequelize(), Sequelize#define() * and on Sequelize/sequelize methods e.g. Sequelize(), Sequelize#define()
*/ */
Hooks.applyTo(Sequelize); Hooks.applyTo(Sequelize);
Hooks.applyTo(Sequelize.prototype);
/** /**
* A general error class * A general error class
......
...@@ -53,10 +53,10 @@ class Transaction { ...@@ -53,10 +53,10 @@ class Transaction {
commit() { commit() {
if (this.finished) { if (this.finished) {
throw new Error('Transaction cannot be committed because it has been finished with state: ' + this.finished); return Utils.Promise.reject(new Error('Transaction cannot be committed because it has been finished with state: ' + this.finished));
} }
this.$clearCls(); this._clearCls();
return this return this
.sequelize .sequelize
...@@ -79,10 +79,10 @@ class Transaction { ...@@ -79,10 +79,10 @@ class Transaction {
rollback() { rollback() {
if (this.finished) { if (this.finished) {
throw new Error('Transaction cannot be rolled back because it has been finished with state: ' + this.finished); return Utils.Promise.reject(new Error('Transaction cannot be rolled back because it has been finished with state: ' + this.finished));
} }
this.$clearCls(); this._clearCls();
return this return this
.sequelize .sequelize
...@@ -154,7 +154,7 @@ class Transaction { ...@@ -154,7 +154,7 @@ class Transaction {
return res; return res;
} }
$clearCls () { _clearCls () {
const cls = this.sequelize.constructor.cls; const cls = this.sequelize.constructor.cls;
if (cls) { if (cls) {
......
...@@ -36,7 +36,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -36,7 +36,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
}); });
break; break;
default: default:
this.sequelize.connectionManager.$clearTypeParser(); this.sequelize.connectionManager._clearTypeParser();
} }
this.sequelize.connectionManager.refreshTypeParser(DataTypes[dialect]); // Reload custom parsers this.sequelize.connectionManager.refreshTypeParser(DataTypes[dialect]); // Reload custom parsers
...@@ -49,7 +49,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -49,7 +49,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
var stringify = Sequelize.DATE.prototype.stringify = sinon.spy(function (value, options) { var stringify = Sequelize.DATE.prototype.stringify = sinon.spy(function (value, options) {
if (!moment.isMoment(value)) { if (!moment.isMoment(value)) {
value = this.$applyTimezone(value, options); value = this._applyTimezone(value, options);
} }
return value.format('YYYY-MM-DD HH:mm:ss Z'); return value.format('YYYY-MM-DD HH:mm:ss Z');
}); });
......
...@@ -82,8 +82,8 @@ describe('Connction Manager', function() { ...@@ -82,8 +82,8 @@ describe('Connction Manager', function() {
}); });
}); });
var connectStub = sandbox.stub(connectionManager, '$connect').returns(resolvedPromise); var connectStub = sandbox.stub(connectionManager, '_connect').returns(resolvedPromise);
sandbox.stub(connectionManager, '$disconnect').returns(resolvedPromise); sandbox.stub(connectionManager, '_disconnect').returns(resolvedPromise);
sandbox.stub(sequelize, 'databaseVersion').returns(resolvedPromise); sandbox.stub(sequelize, 'databaseVersion').returns(resolvedPromise);
connectionManager.initPools(); connectionManager.initPools();
...@@ -128,8 +128,8 @@ describe('Connction Manager', function() { ...@@ -128,8 +128,8 @@ describe('Connction Manager', function() {
}); });
}); });
var connectStub = sandbox.stub(connectionManager, '$connect').returns(resolvedPromise); var connectStub = sandbox.stub(connectionManager, '_connect').returns(resolvedPromise);
sandbox.stub(connectionManager, '$disconnect').returns(resolvedPromise); sandbox.stub(connectionManager, '_disconnect').returns(resolvedPromise);
sandbox.stub(sequelize, 'databaseVersion').returns(resolvedPromise); sandbox.stub(sequelize, 'databaseVersion').returns(resolvedPromise);
connectionManager.initPools(); connectionManager.initPools();
......
...@@ -532,12 +532,12 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -532,12 +532,12 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
return Book.findOne({ return Book.findOne({
where: { id: book.id } where: { id: book.id }
}).then(function(leBook) { }).then(function(leBook) {
var oldOptions = leBook.$options; var oldOptions = leBook._options;
return leBook.reload({ return leBook.reload({
include: [Page] include: [Page]
}).then(function(leBook) { }).then(function(leBook) {
expect(oldOptions).not.to.equal(leBook.$options); expect(oldOptions).not.to.equal(leBook._options);
expect(leBook.$options.include.length).to.equal(1); expect(leBook._options.include.length).to.equal(1);
expect(leBook.Pages.length).to.equal(1); expect(leBook.Pages.length).to.equal(1);
expect(leBook.get({plain: true}).Pages.length).to.equal(1); expect(leBook.get({plain: true}).Pages.length).to.equal(1);
}); });
......
...@@ -10,7 +10,7 @@ var chai = require('chai') ...@@ -10,7 +10,7 @@ var chai = require('chai')
, Promise = Sequelize.Promise; , Promise = Sequelize.Promise;
describe('connection manager', function () { describe('connection manager', function () {
describe('$connect', function () { describe('_connect', function () {
beforeEach(function () { beforeEach(function () {
this.sinon = sinon.sandbox.create(); this.sinon = sinon.sandbox.create();
...@@ -35,7 +35,7 @@ describe('connection manager', function () { ...@@ -35,7 +35,7 @@ describe('connection manager', function () {
var config = {}; var config = {};
return expect(connectionManager.$connect(config)).to.eventually.equal(connection).then(function () { return expect(connectionManager._connect(config)).to.eventually.equal(connection).then(function () {
expect(this.dialect.connectionManager.connect).to.have.been.calledWith(config); expect(this.dialect.connectionManager.connect).to.have.been.calledWith(config);
}.bind(this)); }.bind(this));
}); });
...@@ -52,7 +52,7 @@ describe('connection manager', function () { ...@@ -52,7 +52,7 @@ describe('connection manager', function () {
var connectionManager = new ConnectionManager(this.dialect, this.sequelize); var connectionManager = new ConnectionManager(this.dialect, this.sequelize);
return connectionManager.$connect({}).then(function () { return connectionManager._connect({}).then(function () {
expect(this.dialect.connectionManager.connect).to.have.been.calledWith({ expect(this.dialect.connectionManager.connect).to.have.been.calledWith({
username: username, username: username,
password: password password: password
......
...@@ -33,10 +33,10 @@ describe('[MSSQL] Connection Manager', function () { ...@@ -33,10 +33,10 @@ describe('[MSSQL] Connection Manager', function () {
, config); , config);
}); });
it('connectionManager.$connect() Does not delete `domain` from config.dialectOptions', it('connectionManager._connect() Does not delete `domain` from config.dialectOptions',
function () { function () {
expect(config.dialectOptions.domain).to.equal('TEST.COM'); expect(config.dialectOptions.domain).to.equal('TEST.COM');
instance.dialect.connectionManager.$connect(config); instance.dialect.connectionManager._connect(config);
expect(config.dialectOptions.domain).to.equal('TEST.COM'); expect(config.dialectOptions.domain).to.equal('TEST.COM');
}); });
}); });
...@@ -17,7 +17,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -17,7 +17,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it('can expand nested self-reference', function () { it('can expand nested self-reference', function () {
var options = { include: [{ all: true, nested: true }] }; var options = { include: [{ all: true, nested: true }] };
current.Model.$expandIncludeAll.call(Referral, options); current.Model._expandIncludeAll.call(Referral, options);
expect(options.include).to.deep.equal([ expect(options.include).to.deep.equal([
{ model: Referral } { model: Referral }
...@@ -25,7 +25,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -25,7 +25,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
describe('$validateIncludedElements', function () { describe('_validateIncludedElements', function () {
beforeEach(function () { beforeEach(function () {
this.User = this.sequelize.define('User'); this.User = this.sequelize.define('User');
this.Task = this.sequelize.define('Task', { this.Task = this.sequelize.define('Task', {
...@@ -49,7 +49,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -49,7 +49,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
describe('attributes', function () { describe('attributes', function () {
it('should not inject the aliassed PK again, if its already there', function () { it('should not inject the aliassed PK again, if its already there', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{ {
...@@ -61,7 +61,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -61,7 +61,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(options.include[0].attributes).to.deep.equal([['field_id', 'id'], 'name']); expect(options.include[0].attributes).to.deep.equal([['field_id', 'id'], 'name']);
options = Sequelize.Model.$validateIncludedElements(options); options = Sequelize.Model._validateIncludedElements(options);
// Calling validate again shouldn't add the pk again // Calling validate again shouldn't add the pk again
expect(options.include[0].attributes).to.deep.equal([['field_id', 'id'], 'name']); expect(options.include[0].attributes).to.deep.equal([['field_id', 'id'], 'name']);
...@@ -69,7 +69,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -69,7 +69,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
describe('include / exclude', function () { describe('include / exclude', function () {
it('allows me to include additional attributes', function () { it('allows me to include additional attributes', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{ {
...@@ -92,7 +92,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -92,7 +92,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('allows me to exclude attributes', function () { it('allows me to exclude attributes', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{ {
...@@ -113,7 +113,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -113,7 +113,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('include takes precendence over exclude', function () { it('include takes precendence over exclude', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{ {
...@@ -174,7 +174,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -174,7 +174,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('adds the default scope to where', function () { it('adds the default scope to where', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [{ model: this.Project }] include: [{ model: this.Project }]
}); });
...@@ -183,7 +183,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -183,7 +183,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('adds the where from a scoped model', function () { it('adds the where from a scoped model', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [{ model: this.Project.scope('that') }] include: [{ model: this.Project.scope('that') }]
}); });
...@@ -193,7 +193,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -193,7 +193,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('adds the attributes from a scoped model', function () { it('adds the attributes from a scoped model', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [{ model: this.Project.scope('attr') }] include: [{ model: this.Project.scope('attr') }]
}); });
...@@ -202,7 +202,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -202,7 +202,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('merges where with the where from a scoped model', function () { it('merges where with the where from a scoped model', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [{ where: { active: false }, model: this.Project.scope('that') }] include: [{ where: { active: false }, model: this.Project.scope('that') }]
}); });
...@@ -211,7 +211,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -211,7 +211,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('add the where from a scoped associated model', function () { it('add the where from a scoped associated model', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [{ model: this.Project, as: 'thisProject' }] include: [{ model: this.Project, as: 'thisProject' }]
}); });
...@@ -220,7 +220,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -220,7 +220,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('handles a scope with an aliased column (.field)', function () { it('handles a scope with an aliased column (.field)', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [{ model: this.Project.scope('foobar') }] include: [{ model: this.Project.scope('foobar') }]
}); });
...@@ -231,7 +231,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -231,7 +231,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
describe('duplicating', function () { describe('duplicating', function () {
it('should tag a hasMany association as duplicating: true if undefined', function () { it('should tag a hasMany association as duplicating: true if undefined', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
this.User.Tasks this.User.Tasks
...@@ -242,7 +242,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -242,7 +242,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should respect include.duplicating for a hasMany', function () { it('should respect include.duplicating for a hasMany', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Tasks, duplicating: false} {association: this.User.Tasks, duplicating: false}
...@@ -255,7 +255,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -255,7 +255,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
describe('subQuery', function () { describe('subQuery', function () {
it('should be true if theres a duplicating association', function () { it('should be true if theres a duplicating association', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Tasks} {association: this.User.Tasks}
...@@ -267,7 +267,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -267,7 +267,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should be false if theres a duplicating association but no limit', function () { it('should be false if theres a duplicating association but no limit', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Tasks} {association: this.User.Tasks}
...@@ -279,7 +279,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -279,7 +279,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should be true if theres a nested duplicating association', function () { it('should be true if theres a nested duplicating association', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Company, include: [ {association: this.User.Company, include: [
...@@ -293,7 +293,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -293,7 +293,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should be false if theres a nested duplicating association but no limit', function () { it('should be false if theres a nested duplicating association but no limit', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Company, include: [ {association: this.User.Company, include: [
...@@ -307,7 +307,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -307,7 +307,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should tag a required hasMany association', function () { it('should tag a required hasMany association', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Tasks, required: true} {association: this.User.Tasks, required: true}
...@@ -321,7 +321,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -321,7 +321,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should not tag a required hasMany association with duplicating false', function () { it('should not tag a required hasMany association with duplicating false', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Tasks, required: true, duplicating: false} {association: this.User.Tasks, required: true, duplicating: false}
...@@ -335,7 +335,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -335,7 +335,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should tag a hasMany association with where', function () { it('should tag a hasMany association with where', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Tasks, where: {title: Math.random().toString()}} {association: this.User.Tasks, where: {title: Math.random().toString()}}
...@@ -349,7 +349,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -349,7 +349,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should not tag a hasMany association with where and duplicating false', function () { it('should not tag a hasMany association with where and duplicating false', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Tasks, where: {title: Math.random().toString()}, duplicating: false} {association: this.User.Tasks, where: {title: Math.random().toString()}, duplicating: false}
...@@ -363,7 +363,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -363,7 +363,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should tag a required belongsTo alongside a duplicating association', function () { it('should tag a required belongsTo alongside a duplicating association', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Company, required: true}, {association: this.User.Company, required: true},
...@@ -377,7 +377,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -377,7 +377,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should not tag a required belongsTo alongside a duplicating association with duplicating false', function () { it('should not tag a required belongsTo alongside a duplicating association with duplicating false', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Company, required: true}, {association: this.User.Company, required: true},
...@@ -391,7 +391,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -391,7 +391,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should tag a belongsTo association with where alongside a duplicating association', function () { it('should tag a belongsTo association with where alongside a duplicating association', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Company, where: {name: Math.random().toString()}}, {association: this.User.Company, where: {name: Math.random().toString()}},
...@@ -405,7 +405,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -405,7 +405,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should tag a required belongsTo association alongside a duplicating association with a nested belongsTo', function () { it('should tag a required belongsTo association alongside a duplicating association with a nested belongsTo', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Company, required: true, include: [ {association: this.User.Company, required: true, include: [
...@@ -423,7 +423,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -423,7 +423,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should tag a belongsTo association with where alongside a duplicating association with duplicating false', function () { it('should tag a belongsTo association with where alongside a duplicating association with duplicating false', function () {
var options = Sequelize.Model.$validateIncludedElements({ var options = Sequelize.Model._validateIncludedElements({
model: this.User, model: this.User,
include: [ include: [
{association: this.User.Company, where: {name: Math.random().toString()}}, {association: this.User.Company, where: {name: Math.random().toString()}},
......
...@@ -16,49 +16,49 @@ describe(Support.getTestDialectTeaser('Model') + 'Schemas', function() { ...@@ -16,49 +16,49 @@ describe(Support.getTestDialectTeaser('Model') + 'Schemas', function() {
describe('schema', function() { describe('schema', function() {
it('should work with no default schema', function() { it('should work with no default schema', function() {
expect(Project.$schema).to.be.null; expect(Project._schema).to.be.null;
}); });
it('should apply default schema from define', function() { it('should apply default schema from define', function() {
expect(Company.$schema).to.equal('default'); expect(Company._schema).to.equal('default');
}); });
it('should be able to override the default schema', function() { it('should be able to override the default schema', function() {
expect(Company.schema('newSchema').$schema).to.equal('newSchema'); expect(Company.schema('newSchema')._schema).to.equal('newSchema');
}); });
it('should be able nullify schema', function() { it('should be able nullify schema', function() {
expect(Company.schema(null).$schema).to.be.null; expect(Company.schema(null)._schema).to.be.null;
}); });
it('should support multiple, coexistent schema models', function() { it('should support multiple, coexistent schema models', function() {
var schema1 = Company.schema('schema1') var schema1 = Company.schema('schema1')
, schema2 = Company.schema('schema1'); , schema2 = Company.schema('schema1');
expect(schema1.$schema).to.equal('schema1'); expect(schema1._schema).to.equal('schema1');
expect(schema2.$schema).to.equal('schema1'); expect(schema2._schema).to.equal('schema1');
}); });
}); });
describe('schema delimiter', function() { describe('schema delimiter', function() {
it('should work with no default schema delimiter', function() { it('should work with no default schema delimiter', function() {
expect(Project.$schemaDelimiter).to.equal(''); expect(Project._schemaDelimiter).to.equal('');
}); });
it('should apply default schema delimiter from define', function() { it('should apply default schema delimiter from define', function() {
expect(Company.$schemaDelimiter).to.equal('&'); expect(Company._schemaDelimiter).to.equal('&');
}); });
it('should be able to override the default schema delimiter', function() { it('should be able to override the default schema delimiter', function() {
expect(Company.schema(Company.$schema,'^').$schemaDelimiter).to.equal('^'); expect(Company.schema(Company._schema,'^')._schemaDelimiter).to.equal('^');
}); });
it('should support multiple, coexistent schema delimiter models', function() { it('should support multiple, coexistent schema delimiter models', function() {
var schema1 = Company.schema(Company.$schema,'$') var schema1 = Company.schema(Company._schema,'$')
, schema2 = Company.schema(Company.$schema,'#'); , schema2 = Company.schema(Company._schema,'#');
expect(schema1.$schemaDelimiter).to.equal('$'); expect(schema1._schemaDelimiter).to.equal('$');
expect(schema2.$schemaDelimiter).to.equal('#'); expect(schema2._schemaDelimiter).to.equal('#');
}); });
}); });
} }
......
...@@ -91,7 +91,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -91,7 +91,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should be able to exclude in defaultScope #4735', function () { it('should be able to exclude in defaultScope #4735', function () {
expect(User.$scope.attributes).to.deep.equal([ expect(User._scope.attributes).to.deep.equal([
'id', 'id',
'name', 'name',
'createdAt', 'createdAt',
...@@ -100,7 +100,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -100,7 +100,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should be able to exclude in a scope #4925', function () { it('should be able to exclude in a scope #4925', function () {
expect(User.scope('aScope').$scope.attributes).to.deep.equal([ expect(User.scope('aScope')._scope.attributes).to.deep.equal([
'id', 'id',
'name', 'name',
'createdAt', 'createdAt',
...@@ -112,25 +112,25 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -112,25 +112,25 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it('defaultScope should be an empty object if not overridden', function () { it('defaultScope should be an empty object if not overridden', function () {
var Foo = current.define('foo', {}, {}); var Foo = current.define('foo', {}, {});
expect(Foo.scope('defaultScope').$scope).to.deep.equal({}); expect(Foo.scope('defaultScope')._scope).to.deep.equal({});
}); });
it('should apply default scope', function () { it('should apply default scope', function () {
expect(Company.$scope).to.deep.equal({ expect(Company._scope).to.deep.equal({
include: [{ model: Project }], include: [{ model: Project }],
where: { active: true } where: { active: true }
}); });
}); });
it('should be able to unscope', function () { it('should be able to unscope', function () {
expect(Company.scope(null).$scope).to.be.empty; expect(Company.scope(null)._scope).to.be.empty;
expect(Company.unscoped().$scope).to.be.empty; expect(Company.unscoped()._scope).to.be.empty;
// Yes, being unscoped is also a scope - this prevents inject defaultScope, when including a scoped model, see #4663 // Yes, being unscoped is also a scope - this prevents inject defaultScope, when including a scoped model, see #4663
expect(Company.unscoped().scoped).to.be.ok; expect(Company.unscoped().scoped).to.be.ok;
}); });
it('should be able to merge scopes', function() { it('should be able to merge scopes', function() {
expect(Company.scope('somethingTrue', 'somethingFalse').$scope).to.deep.equal({ expect(Company.scope('somethingTrue', 'somethingFalse')._scope).to.deep.equal({
where: { where: {
something: false, something: false,
somethingElse: 42 somethingElse: 42
...@@ -143,18 +143,18 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -143,18 +143,18 @@ describe(Support.getTestDialectTeaser('Model'), function() {
var scoped1 = Company.scope('somethingTrue') var scoped1 = Company.scope('somethingTrue')
, scoped2 = Company.scope('somethingFalse'); , scoped2 = Company.scope('somethingFalse');
expect(scoped1.$scope).to.deep.equal(scopes.somethingTrue); expect(scoped1._scope).to.deep.equal(scopes.somethingTrue);
expect(scoped2.$scope).to.deep.equal(scopes.somethingFalse); expect(scoped2._scope).to.deep.equal(scopes.somethingFalse);
}); });
it('should work with function scopes', function () { it('should work with function scopes', function () {
expect(Company.scope({method: ['actualValue', 11]}).$scope).to.deep.equal({ expect(Company.scope({method: ['actualValue', 11]})._scope).to.deep.equal({
where: { where: {
other_value: 11 other_value: 11
} }
}); });
expect(Company.scope('noArgs').$scope).to.deep.equal({ expect(Company.scope('noArgs')._scope).to.deep.equal({
where: { where: {
other_value: 7 other_value: 7
} }
...@@ -162,7 +162,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -162,7 +162,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should be able to merge two scoped includes', function () { it('should be able to merge two scoped includes', function () {
expect(Company.scope('users', 'projects').$scope).to.deep.equal({ expect(Company.scope('users', 'projects')._scope).to.deep.equal({
include: [ include: [
{ model: User }, { model: User },
{ model: Project } { model: Project }
...@@ -171,11 +171,11 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -171,11 +171,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should be able to override the default scope', function() { it('should be able to override the default scope', function() {
expect(Company.scope('somethingTrue').$scope).to.deep.equal(scopes.somethingTrue); expect(Company.scope('somethingTrue')._scope).to.deep.equal(scopes.somethingTrue);
}); });
it('should be able to combine default with another scope', function () { it('should be able to combine default with another scope', function () {
expect(Company.scope(['defaultScope', {method: ['actualValue', 11]}]).$scope).to.deep.equal({ expect(Company.scope(['defaultScope', {method: ['actualValue', 11]}])._scope).to.deep.equal({
include: [{ model: Project }], include: [{ model: Project }],
where: { where: {
active: true, active: true,
...@@ -185,13 +185,13 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -185,13 +185,13 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('should be able to use raw queries', function () { it('should be able to use raw queries', function () {
expect(Company.scope([{method: ['complexFunction', 'qux']}]).$scope).to.deep.equal({ expect(Company.scope([{method: ['complexFunction', 'qux']}])._scope).to.deep.equal({
where: [ 'qux IN (SELECT foobar FROM some_sql_function(foo.bar))' ] where: [ 'qux IN (SELECT foobar FROM some_sql_function(foo.bar))' ]
}); });
}); });
it('should override the default scope', function () { it('should override the default scope', function () {
expect(Company.scope(['defaultScope', {method: ['complexFunction', 'qux']}]).$scope).to.deep.equal({ expect(Company.scope(['defaultScope', {method: ['complexFunction', 'qux']}])._scope).to.deep.equal({
include: [{ model: Project }], include: [{ model: Project }],
where: [ 'qux IN (SELECT foobar FROM some_sql_function(foo.bar))' ] where: [ 'qux IN (SELECT foobar FROM some_sql_function(foo.bar))' ]
}); });
...@@ -225,7 +225,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -225,7 +225,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
include: [Project] include: [Project]
}); });
expect(Company.scope('newScope').$scope).to.deep.equal({ expect(Company.scope('newScope')._scope).to.deep.equal({
where: { this: 'that' }, where: { this: 'that' },
include: [{ model: Project }] include: [{ model: Project }]
}); });
...@@ -244,7 +244,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -244,7 +244,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
} }
}, { override: true }); }, { override: true });
expect(Company.scope('somethingTrue').$scope).to.deep.equal({ expect(Company.scope('somethingTrue')._scope).to.deep.equal({
where: { something: false }, where: { something: false },
}); });
}); });
...@@ -260,7 +260,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -260,7 +260,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
include: [Project] include: [Project]
}, { override: true }); }, { override: true });
expect(Company.$scope).to.deep.equal({ expect(Company._scope).to.deep.equal({
include: [{ model: Project }] include: [{ model: Project }]
}); });
}); });
...@@ -273,14 +273,14 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -273,14 +273,14 @@ describe(Support.getTestDialectTeaser('Model'), function() {
} }
}); });
expect(Company.scope('newIncludeScope').$scope).to.deep.equal({ expect(Company.scope('newIncludeScope')._scope).to.deep.equal({
attributes: ['id', 'updatedAt', 'foobar'] attributes: ['id', 'updatedAt', 'foobar']
}); });
}); });
}); });
describe('$injectScope', function () { describe('_injectScope', function () {
it('should be able to merge scope and where', function () { it('should be able to merge scope and where', function () {
var scope = { var scope = {
where: { where: {
...@@ -298,8 +298,8 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -298,8 +298,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
limit: 9 limit: 9
}; };
current.Model.$injectScope.call({ current.Model._injectScope.call({
$scope: scope _scope: scope
}, options); }, options);
expect(options).to.deep.equal({ expect(options).to.deep.equal({
...@@ -322,8 +322,8 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -322,8 +322,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
var options = {}; var options = {};
current.Model.$injectScope.call({ current.Model._injectScope.call({
$scope: scope _scope: scope
}, options); }, options);
expect(options.include).to.have.length(1); expect(options.include).to.have.length(1);
...@@ -339,8 +339,8 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -339,8 +339,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
include: [{ model: Project, where: { something: true }}] include: [{ model: Project, where: { something: true }}]
}; };
current.Model.$injectScope.call({ current.Model._injectScope.call({
$scope: scope _scope: scope
}, options); }, options);
expect(options.include).to.have.length(1); expect(options.include).to.have.length(1);
...@@ -356,8 +356,8 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -356,8 +356,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
include: [{model: User, as: 'otherUser'}] include: [{model: User, as: 'otherUser'}]
}; };
current.Model.$injectScope.call({ current.Model._injectScope.call({
$scope: scope _scope: scope
}, options); }, options);
expect(options.include).to.have.length(2); expect(options.include).to.have.length(2);
...@@ -378,8 +378,8 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -378,8 +378,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
] ]
}; };
current.Model.$injectScope.call({ current.Model._injectScope.call({
$scope: scope _scope: scope
}, options); }, options);
expect(options.include).to.have.length(2); expect(options.include).to.have.length(2);
...@@ -401,8 +401,8 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -401,8 +401,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
] ]
}; };
current.Model.$injectScope.call({ current.Model._injectScope.call({
$scope: scope _scope: scope
}, options); }, options);
expect(options.include).to.have.length(2); expect(options.include).to.have.length(2);
...@@ -424,8 +424,8 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -424,8 +424,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
] ]
}; };
current.Model.$injectScope.call({ current.Model._injectScope.call({
$scope: scope _scope: scope
}, options); }, options);
expect(options.include).to.have.length(2); expect(options.include).to.have.length(2);
......
...@@ -29,7 +29,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -29,7 +29,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
}); });
expectsql(sql.addIndexQuery(sql.quoteTable(sql.addSchema({ expectsql(sql.addIndexQuery(sql.quoteTable(sql.addSchema({
$schema: 'schema', _schema: 'schema',
tableName: 'table' tableName: 'table'
})), ['column1', 'column2'], {}), { })), ['column1', 'column2'], {}), {
default: 'CREATE INDEX [schema_table_column1_column2] ON [schema].[table] ([column1], [column2])' default: 'CREATE INDEX [schema_table_column1_column2] ON [schema].[table] ([column1], [column2])'
......
...@@ -79,7 +79,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -79,7 +79,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: false, subQuery: false,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
model: User, model: User,
include: [ include: [
User.Company User.Company
...@@ -92,7 +92,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -92,7 +92,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: false, subQuery: false,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
model: User, model: User,
include: [ include: [
{association: User.Company, where: {public: true}, or: true} {association: User.Company, where: {public: true}, or: true}
...@@ -107,7 +107,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -107,7 +107,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: true, subQuery: true,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
limit: 3, limit: 3,
model: User, model: User,
include: [ include: [
...@@ -122,7 +122,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -122,7 +122,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
model: User, model: User,
subQuery: true, subQuery: true,
groupedLimit: {}, groupedLimit: {},
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
limit: 3, limit: 3,
model: User, model: User,
include: [ include: [
...@@ -136,7 +136,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -136,7 +136,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: true, subQuery: true,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
limit: 3, limit: 3,
model: User, model: User,
include: [ include: [
...@@ -154,7 +154,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -154,7 +154,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: true, subQuery: true,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
limit: 3, limit: 3,
model: User, model: User,
include: [ include: [
...@@ -170,7 +170,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -170,7 +170,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: true, subQuery: true,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
limit: 3, limit: 3,
model: User, model: User,
include: [ include: [
...@@ -188,7 +188,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -188,7 +188,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: true, subQuery: true,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
limit: 3, limit: 3,
model: User, model: User,
include: [ include: [
...@@ -205,7 +205,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -205,7 +205,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: true, subQuery: true,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
limit: 3, limit: 3,
model: User, model: User,
include: [ include: [
...@@ -223,7 +223,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -223,7 +223,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: false, subQuery: false,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
model: User, model: User,
include: [ include: [
User.Tasks User.Tasks
...@@ -236,7 +236,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -236,7 +236,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: true, subQuery: true,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
limit: 3, limit: 3,
model: User, model: User,
include: [ include: [
...@@ -251,7 +251,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -251,7 +251,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: true, subQuery: true,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
limit: 3, limit: 3,
model: User, model: User,
include: [ include: [
...@@ -266,7 +266,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -266,7 +266,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: false, subQuery: false,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
model: User, model: User,
include: [ include: [
{association: User.Tasks, on: { {association: User.Tasks, on: {
...@@ -284,7 +284,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -284,7 +284,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql({ testsql({
model: User, model: User,
subQuery: false, subQuery: false,
include: Sequelize.Model.$validateIncludedElements({ include: Sequelize.Model._validateIncludedElements({
model: User, model: User,
include: [ include: [
{association: User.Tasks, on: {'user_id': {$col: 'User.alternative_id'}}} {association: User.Tasks, on: {'user_id': {$col: 'User.alternative_id'}}}
......
...@@ -120,7 +120,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -120,7 +120,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
Post.Comments = Post.hasMany(Comment, {foreignKey: 'postId', as: 'COMMENTS'}); Post.Comments = Post.hasMany(Comment, {foreignKey: 'postId', as: 'COMMENTS'});
var include = Model.$validateIncludedElements({ var include = Model._validateIncludedElements({
include: [{ include: [{
attributes: ['title'], attributes: ['title'],
association: User.Posts association: User.Posts
...@@ -158,7 +158,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -158,7 +158,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
+') AS [user] LEFT OUTER JOIN [post] AS [POSTS] ON [user].[id] = [POSTS].[user_id];' +') AS [user] LEFT OUTER JOIN [post] AS [POSTS] ON [user].[id] = [POSTS].[user_id];'
}); });
var nestedInclude = Model.$validateIncludedElements({ var nestedInclude = Model._validateIncludedElements({
include: [{ include: [{
attributes: ['title'], attributes: ['title'],
association: User.Posts, association: User.Posts,
...@@ -220,7 +220,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -220,7 +220,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
expectsql(sql.selectQuery('User', { expectsql(sql.selectQuery('User', {
attributes: ['name', 'age'], attributes: ['name', 'age'],
include: Model.$validateIncludedElements({ include: Model._validateIncludedElements({
include: [{ include: [{
attributes: ['title'], attributes: ['title'],
association: User.Posts association: User.Posts
...@@ -277,7 +277,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -277,7 +277,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
expectsql(sql.selectQuery('User', { expectsql(sql.selectQuery('User', {
attributes: ['name', 'age'], attributes: ['name', 'age'],
include: Model.$validateIncludedElements({ include: Model._validateIncludedElements({
include: [{ include: [{
attributes: ['title'], attributes: ['title'],
association: User.Posts association: User.Posts
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!