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

Commit ecbc1839 by Greenkeeper Committed by Jan Aagaard Meier

Update lodash to version 4.11.1 馃殌 (#5745)

* chore(package): update lodash to version 4.11.1

http://greenkeeper.io/

* chore(package): Work around issues with lodash.merge cloning
1 parent 83ed07c7
......@@ -8,6 +8,7 @@
- [FIXED] Support calling `setAssociation` twice on `hasOne` [#5315](https://github.com/sequelize/sequelize/issues/5315)
- [INTERNALS] Removed dependency on wellknown in favor of terraformer-wkt-parser
- [ADDED] Benchmarking feature [#2494](https://github.com/sequelize/sequelize/issues/2494)
- [INTERNALS] Add `Utils.mergeDeep` - allows lodash to be updated to latest version
# 3.20.0
- [ADDED] rejectOnEmpty mode [#272](https://github.com/sequelize/sequelize/issues/272) [#5480](https://github.com/sequelize/sequelize/issues/5480)
......
......@@ -160,7 +160,7 @@ var BelongsToMany = function(source, target, options) {
if (!this.sequelize.isDefined(this.through.model)) {
this.through.model = this.sequelize.define(this.through.model, {}, _.extend(this.options, {
tableName: this.through.model,
indexes: {}, //we dont want indexes here (as referenced in #2416)
indexes: [], //we don't want indexes here (as referenced in #2416)
paranoid: false, // A paranoid join table does not make sense
validate: {} // Don't propagate model-level validations
}));
......
......@@ -598,19 +598,18 @@ Sequelize.prototype.define = function(modelName, attributes, options) { // testh
var globalOptions = this.options;
if (globalOptions.define) {
options = Utils._.merge({}, globalOptions.define, options);
options = Utils.merge(globalOptions.define, options);
}
options = Utils._.merge({
options = Utils.merge({
name: {
plural: Utils.inflection.pluralize(modelName),
singular: Utils.inflection.singularize(modelName)
},
indexes: []
indexes: [],
omitNul: globalOptions.omitNull
}, options);
options.omitNull = globalOptions.omitNull;
// if you call "define" multiple times for the same modelName, do not clutter the factory
if (this.isDefined(modelName)) {
this.modelManager.removeModel(this.modelManager.getModel(modelName));
......
......@@ -42,6 +42,30 @@ var Utils = module.exports = {
}
}.bind(this));
},
// An alternative to _.merge, which doesn't clone its arguments
// Cloning is a bad idea because options arguments may contain references to sequelize
// models - which again reference database libs which don't like to be cloned (in particular pg-native)
merge: function () {
var result = {};
Array.prototype.slice.apply(arguments).forEach(function (obj) {
_.forOwn(obj, function (value, key) {
if (typeof value !== 'undefined') {
if (!result[key]) {
result[key] = value;
} else if (_.isPlainObject(value) && _.isPlainObject(result[key])) {
result[key] = Utils.merge(result[key], value);
} else if (Array.isArray(value) && Array.isArray(result[key])) {
result[key] = value.concat(result[key]);
} else {
result[key] = value;
}
}
});
});
return result;
},
lowercaseFirst: function (s) {
return s[0].toLowerCase() + s.slice(1);
},
......
......@@ -37,7 +37,7 @@
"dottie": "^1.0.0",
"generic-pool": "2.4.2",
"inflection": "^1.6.0",
"lodash": "4.3.0",
"lodash": "4.11.1",
"moment": "^2.11.2",
"moment-timezone": "^0.5.3",
"node-uuid": "~1.4.4",
......
......@@ -9,6 +9,16 @@ var chai = require('chai')
// Notice: [] will be replaced by dialect specific tick/quote character when there is not dialect specific expectation but only a default expectation
suite(Support.getTestDialectTeaser('Utils'), function() {
suite('merge', function () {
test('does not clone sequelize models', function () {
var User = this.sequelize.define('user')
, merged = Utils.merge({}, { include: [{model : User }]})
, merged2 = Utils.merge({}, { user: User });
expect(merged.include[0].model).to.equal(User);
expect(merged2.user).to.equal(User);
});
});
suite('toDefaultValue', function () {
test('return plain data types', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!