涓嶈鎬傦紝灏辨槸骞诧紝鎾歌捣琚栧瓙骞诧紒

Commit 046620a6 by Jan Aagaard Meier

Merge pull request #5336 from sequelize/greenkeeper-lodash-4.1.0

Update lodash to version 4.1.0 馃殌
2 parents 2efa123a e739d816
......@@ -154,7 +154,7 @@ var BelongsToMany = function(source, target, options) {
this.paired = association;
association.paired = this;
}
}, this);
}.bind(this));
if (typeof this.through.model === 'string') {
if (!this.sequelize.isDefined(this.through.model)) {
......@@ -668,7 +668,7 @@ BelongsToMany.prototype.injectSetter = function(obj) {
var throughAttributes = obj[association.through.model.name]
, attributes = _.defaults({}, throughAttributes, defaultAttributes);
if (_.any(Object.keys(attributes), function (attribute) {
if (_.some(Object.keys(attributes), function (attribute) {
return attributes[attribute] !== existingAssociation[attribute];
})) {
changedAssociations.push(obj);
......
......@@ -772,7 +772,7 @@ var ENUM = ABSTRACT.inherits(function(value) {
ENUM.prototype.key = ENUM.key = 'ENUM';
ENUM.prototype.validate = function(value) {
if (!_.contains(this.values, value)) {
if (!_.includes(this.values, value)) {
throw new sequelizeErrors.ValidationError(util.format('%j is not a valid choice in %j', value, this.values));
}
......
......@@ -59,7 +59,7 @@ ConnectionManager.prototype.refreshTypeParser = function(dataTypes) {
throw new Error('Parse function not supported for type ' + dataType.key + ' in dialect ' + this.dialectName);
}
}
}, this);
}.bind(this));
};
ConnectionManager.prototype.onProcessExit = function() {
......
......@@ -1498,7 +1498,7 @@ var QueryGenerator = {
var validateOrder = function(order) {
if (order instanceof Utils.literal) return;
if (!_.contains([
if (!_.includes([
'ASC',
'DESC',
'ASC NULLS LAST',
......@@ -2215,7 +2215,7 @@ var QueryGenerator = {
value = this.whereItemQuery(null, value);
}
}
}, this);
}.bind(this));
}
if (comparator === '=' && value === null) {
......
......@@ -5,7 +5,8 @@ var AbstractConnectionManager = require('../abstract/connection-manager')
, Utils = require('../../utils')
, Promise = require('../../promise')
, sequelizeErrors = require('../../errors')
, parserStore = require('../parserStore')('mssql');
, parserStore = require('../parserStore')('mssql')
, _ = require('lodash');
ConnectionManager = function(dialect, sequelize) {
AbstractConnectionManager.call(this, dialect, sequelize);
......@@ -76,9 +77,9 @@ ConnectionManager.prototype.connect = function(config) {
switch (err.code) {
case 'ESOCKET':
if (Utils._.contains(err.message, 'connect EHOSTUNREACH')) {
if (_.includes(err.message, 'connect EHOSTUNREACH')) {
reject(new sequelizeErrors.HostNotReachableError(err));
} else if (Utils._.contains(err.message, 'connect ECONNREFUSED')) {
} else if (_.includes(err.message, 'connect ECONNREFUSED')) {
reject(new sequelizeErrors.ConnectionRefusedError(err));
} else {
reject(new sequelizeErrors.ConnectionError(err));
......
......@@ -3,7 +3,8 @@
var Utils = require('../../utils')
, AbstractQuery = require('../abstract/query')
, sequelizeErrors = require('../../errors.js')
, parserStore = require('../parserStore')('mssql');
, parserStore = require('../parserStore')('mssql'),
_ = require('lodash');
var Query = function(connection, sequelize, options) {
this.connection = connection;
......@@ -41,7 +42,7 @@ Query.prototype.run = function(sql, parameters) {
var promise = new Utils.Promise(function(resolve, reject) {
// TRANSACTION SUPPORT
if (Utils._.contains(self.sql, 'BEGIN TRANSACTION')) {
if (_.includes(self.sql, 'BEGIN TRANSACTION')) {
self.connection.beginTransaction(function(err) {
if (!!err) {
reject(self.formatError(err));
......@@ -49,7 +50,7 @@ Query.prototype.run = function(sql, parameters) {
resolve(self.formatResults());
}
} /* name, isolation_level */);
} else if (Utils._.contains(self.sql, 'COMMIT TRANSACTION')) {
} else if (_.includes(self.sql, 'COMMIT TRANSACTION')) {
self.connection.commitTransaction(function(err) {
if (!!err) {
reject(self.formatError(err));
......@@ -57,7 +58,7 @@ Query.prototype.run = function(sql, parameters) {
resolve(self.formatResults());
}
});
} else if (Utils._.contains(self.sql, 'ROLLBACK TRANSACTION')) {
} else if (_.includes(self.sql, 'ROLLBACK TRANSACTION')) {
self.connection.rollbackTransaction(function(err) {
if (!!err) {
reject(self.formatError(err));
......@@ -256,7 +257,7 @@ Query.prototype.isShowIndexesQuery = function () {
Query.prototype.handleShowIndexesQuery = function (data) {
// Group by index name, and collect all fields
data = Utils._.foldl(data, function (acc, item) {
data = _.reduce(data, function (acc, item) {
if (!(item.index_name in acc)) {
acc[item.index_name] = item;
item.fields = [];
......
......@@ -3,7 +3,8 @@
var Utils = require('../../utils')
, AbstractQuery = require('../abstract/query')
, uuid = require('node-uuid')
, sequelizeErrors = require('../../errors.js');
, sequelizeErrors = require('../../errors.js')
, _ = require('lodash');
var Query = function(connection, sequelize, options) {
this.connection = connection;
......@@ -176,7 +177,7 @@ Query.prototype.formatError = function (err) {
Query.prototype.handleShowIndexesQuery = function (data) {
// Group by index name, and collect all fields
data = Utils._.foldl(data, function (acc, item) {
data = _.reduce(data, function (acc, item) {
if (!(item.Key_name in acc)) {
acc[item.Key_name] = item;
item.fields = [];
......
......@@ -6,7 +6,8 @@ var Utils = require('../../utils')
, DataTypes = require('../../data-types')
, AbstractQueryGenerator = require('../abstract/query-generator')
, primaryKeys = {}
, semver = require('semver');
, semver = require('semver')
, _ = require('lodash');
var QueryGenerator = {
options: {},
......@@ -141,14 +142,13 @@ var QueryGenerator = {
},
handleSequelizeMethod: function (smth, tableName, factory, options, prepend) {
var _ = Utils._;
if (smth instanceof Utils.json) {
// Parse nested object
if (smth.conditions) {
var conditions = _.map(this.parseConditionObject(smth.conditions), function generateSql(condition) {
return util.format("%s#>>'{%s}' = '%s'",
_.first(condition.path),
_.rest(condition.path).join(','),
_.tail(condition.path).join(','),
condition.value);
});
......@@ -157,14 +157,14 @@ var QueryGenerator = {
var str;
// Allow specifying conditions using the postgres json syntax
if (_.any(['->', '->>', '#>'], _.partial(_.contains, smth.path))) {
if (_.some(['->', '->>', '#>'], _.partial(_.includes, smth.path))) {
str = smth.path;
} else {
// Also support json dot notation
var path = smth.path.split('.');
str = util.format("%s#>>'{%s}'",
_.first(path),
_.rest(path).join(','));
_.first(path),
_.tail(path).join(','));
}
if (smth.value) {
......
......@@ -427,9 +427,9 @@ Instance.prototype.previous = function(key) {
return this._previousDataValues[key];
}
return _.pick(this._previousDataValues, function(value, key) {
return _.pickBy(this._previousDataValues, function(value, key) {
return this.changed(key);
}, this);
}.bind(this));
};
Instance.prototype._setInclude = function(key, value, options) {
......@@ -591,7 +591,7 @@ Instance.prototype.save = function(options) {
}
});
options.fields = _.unique(options.fields.concat(hookChanged));
options.fields = _.uniq(options.fields.concat(hookChanged));
}
if (hookChanged) {
......@@ -1043,7 +1043,7 @@ Instance.prototype.equals = function(other) {
Instance.prototype.equalsOneOf = function(others) {
var self = this;
return _.any(others, function(other) {
return _.some(others, function(other) {
return self.equals(other);
});
};
......
......@@ -64,17 +64,17 @@ var Model = function(name, attributes, options) {
this.$schemaDelimiter = this.options.schemaDelimiter;
// error check options
Utils._.each(options.validate, function(validator, validatorType) {
if (Utils._.contains(Utils._.keys(attributes), validatorType)) {
_.each(options.validate, function(validator, validatorType) {
if (_.includes(Utils._.keys(attributes), validatorType)) {
throw new Error('A model validator function must not have the same name as a field. Model: ' + name + ', field/validation name: ' + validatorType);
}
if (!Utils._.isFunction(validator)) {
if (!_.isFunction(validator)) {
throw new Error('Members of the validate option must be functions. Model: ' + name + ', error with validate member ' + validatorType);
}
});
this.attributes = this.rawAttributes = Utils._.mapValues(attributes, function(attribute, name) {
this.attributes = this.rawAttributes = _.mapValues(attributes, function(attribute, name) {
if (!Utils._.isPlainObject(attribute)) {
attribute = { type: attribute };
}
......@@ -95,15 +95,19 @@ var Model = function(name, attributes, options) {
}
return attribute;
}, this);
}.bind(this));
};
Object.defineProperty(Model.prototype, 'QueryInterface', {
get: function() { return this.modelManager.sequelize.getQueryInterface(); }
get: function() {
return this.modelManager.sequelize.getQueryInterface();
}
});
Object.defineProperty(Model.prototype, 'QueryGenerator', {
get: function() { return this.QueryInterface.QueryGenerator; }
get: function() {
return this.QueryInterface.QueryGenerator;
}
});
Model.prototype.toString = function () {
......@@ -158,7 +162,7 @@ var addDefaultAttributes = function() {
// Add id if no primary key was manually added to definition
// Can't use this.primaryKeys here, since this function is called before PKs are identified
if (!_.any(this.rawAttributes, 'primaryKey')) {
if (!_.some(this.rawAttributes, 'primaryKey')) {
if ('id' in this.rawAttributes) {
// Something is fishy here!
throw new Error("A column called 'id' was added to the attributes of '" + this.tableName + "' but not marked with 'primaryKey: true'");
......@@ -530,7 +534,7 @@ validateIncludedElement = function(include, tableNames, options) {
if (include.attributes.length) {
_.each(include.model.primaryKeys, function (attr, key) {
// Include the primary key if its not already take - take into account that the pk might be aliassed (due to a .field prop)
if (!_.any(include.attributes, function (includeAttr) {
if (!_.some(include.attributes, function (includeAttr) {
if (attr.field !== key) {
return Array.isArray(includeAttr) && includeAttr[0] === attr.field && includeAttr[1] === key;
}
......@@ -698,7 +702,7 @@ Model.prototype.init = function(modelManager) {
if (_.isPlainObject(scope)) {
conformOptions(scope, this);
}
}, this);
}.bind(this));
// Instance prototype
this.Instance = function() {
......@@ -799,7 +803,7 @@ Model.prototype.refreshAttributes = function() {
this.primaryKeys = {};
self.options.uniqueKeys = {};
Utils._.each(this.rawAttributes, function(definition, name) {
_.each(this.rawAttributes, function(definition, name) {
definition.type = self.sequelize.normalizeDataType(definition.type);
definition.Model = self;
......@@ -993,8 +997,8 @@ Model.prototype.sync = function(options) {
// Assign an auto-generated name to indexes which are not named by the user
self.options.indexes = self.QueryInterface.nameIndexes(self.options.indexes, self.tableName);
indexes = Utils._.filter(self.options.indexes, function (item1) {
return !Utils._.any(indexes, function (item2) {
indexes = _.filter(self.options.indexes, function (item1) {
return !_.some(indexes, function (item2) {
return item1.name === item2.name;
});
});
......@@ -1201,7 +1205,7 @@ Model.prototype.scope = function(option) {
}
if (!!scope) {
_.assign(self.$scope, scope, function scopeCustomizer(objectValue, sourceValue, key) {
_.assignWith(self.$scope, scope, function scopeCustomizer(objectValue, sourceValue, key) {
if (key === 'where') {
return Array.isArray(sourceValue) ? sourceValue : _.assign(objectValue || {}, sourceValue);
} else if ( (['attributes','include'].indexOf(key) >= 0) && Array.isArray(objectValue) && Array.isArray(sourceValue)) {
......@@ -1381,7 +1385,6 @@ Model.prototype.findAll = function(options) {
}).then(function() {
originalOptions = optClone(options);
options.tableNames = Object.keys(tableNames);
return this.QueryInterface.select(this, this.getTableName(options), options);
}).tap(function(results) {
if (options.hooks) {
......
......@@ -35,12 +35,12 @@ var Utils = module.exports = {
},
// Same concept as _.merge, but don't overwrite properties that have already been assigned
mergeDefaults: function (a, b) {
return this._.merge(a, b, function (objectValue, sourceValue) {
return _.mergeWith(a, b, function (objectValue, sourceValue) {
// If it's an object, let _ handle it this time, we will be called again for each property
if (!this._.isPlainObject(objectValue) && objectValue !== undefined) {
return objectValue;
}
}, this);
}.bind(this));
},
lowercaseFirst: function (s) {
return s[0].toLowerCase() + s.slice(1);
......@@ -64,7 +64,7 @@ var Utils = module.exports = {
return SqlString.formatNamedParameters(sql, parameters, timeZone, dialect);
},
cloneDeep: function(obj, fn) {
return _.cloneDeep(obj, function (elem) {
return _.cloneDeepWith(obj, function (elem) {
// Do not try to customize cloning of plain objects and strings
if (Array.isArray(elem) || _.isPlainObject(elem)) {
return undefined;
......@@ -89,7 +89,7 @@ var Utils = module.exports = {
}
}.bind(Model));
options.attributes = _.without.apply(_, [options.attributes].concat(Model._virtualAttributes));
options.attributes = _.unique(options.attributes);
options.attributes = _.uniq(options.attributes);
}
Utils.mapOptionFieldNames(options, Model);
......
......@@ -37,7 +37,7 @@
"dottie": "^1.0.0",
"generic-pool": "2.4.0",
"inflection": "^1.6.0",
"lodash": "^3.9.3",
"lodash": "^4.1.0",
"moment": "^2.11.1",
"moment-timezone": "^0.5.0",
"node-uuid": "~1.4.4",
......
......@@ -1780,7 +1780,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
return self.sequelize.getQueryInterface().showAllTables();
}).then(function(result) {
if (dialect === 'mssql' /* current.dialect.supports.schemas */) {
result = _.pluck(result, 'tableName');
result = _.map(result, 'tableName');
}
expect(result.indexOf('group_user')).not.to.equal(-1);
......@@ -1800,7 +1800,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
return self.sequelize.getQueryInterface().showAllTables();
}).then(function(result) {
if (dialect === 'mssql' /* current.dialect.supports.schemas */) {
result = _.pluck(result, 'tableName');
result = _.map(result, 'tableName');
}
expect(result.indexOf('user_groups')).not.to.equal(-1);
......
......@@ -43,7 +43,8 @@ describe(Support.getTestDialectTeaser('associations'), function() {
foreignKey: 'commentable_id',
scope: {
commentable: 'post'
}
},
constraints: false
});
this.Post.hasOne(this.Comment, {
foreignKey: 'commentable_id',
......@@ -51,33 +52,39 @@ describe(Support.getTestDialectTeaser('associations'), function() {
scope: {
commentable: 'post',
isMain: true
}
},
constraints: false
});
this.Comment.belongsTo(this.Post, {
foreignKey: 'commentable_id',
as: 'post'
as: 'post',
constraints: false
});
this.Image.hasMany(this.Comment, {
foreignKey: 'commentable_id',
scope: {
commentable: 'image'
}
},
constraints: false
});
this.Comment.belongsTo(this.Image, {
foreignKey: 'commentable_id',
as: 'image'
as: 'image',
constraints: false
});
this.Question.hasMany(this.Comment, {
foreignKey: 'commentable_id',
scope: {
commentable: 'question'
}
},
constraints: false
});
this.Comment.belongsTo(this.Question, {
foreignKey: 'commentable_id',
as: 'question'
as: 'question',
constraints: false
});
});
......
......@@ -59,7 +59,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
return self.queryInterface.dropAllTables({skip: ['skipme']}).then(function() {
return self.queryInterface.showAllTables().then(function(tableNames) {
if (dialect === 'mssql' /* current.dialect.supports.schemas */) {
tableNames = _.pluck(tableNames, 'tableName');
tableNames = _.map(tableNames, 'tableName');
}
expect(tableNames).to.contain('skipme');
});
......
......@@ -899,7 +899,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
return Photo.sync({ force: true }).then(function() {
return self.sequelize.getQueryInterface().showAllTables().then(function(tableNames) {
if (dialect === 'mssql' /* current.dialect.supports.schemas */) {
tableNames = _.pluck(tableNames, 'tableName');
tableNames = _.map(tableNames, 'tableName');
}
expect(tableNames).to.include('photos');
});
......
......@@ -21,7 +21,6 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
this.sinon.restore();
});
this.timeout(5000);
describe('constructor', function() {
it('stores options', function() {
var transaction = new Transaction(this.sequelize);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!