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

Commit df279741 by Jan Aagaard Meier

Fix #1891, and refactor all tests in assocations/has-many.test.js to use promises <3

1 parent 5ff679fe
...@@ -18,6 +18,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell ...@@ -18,6 +18,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- [BUG] Transactions now use the pool so you will never go over your pool defined connection limit - [BUG] Transactions now use the pool so you will never go over your pool defined connection limit
- [BUG] Fix use of Sequelize.literal in eager loading and when renaming attributes [#1916](https://github.com/sequelize/sequelize/pull/1916) - [BUG] Fix use of Sequelize.literal in eager loading and when renaming attributes [#1916](https://github.com/sequelize/sequelize/pull/1916)
- [BUG] Use the provided name for a unique index if one is given, instead of concating the column names together [#1944](https://github.com/sequelize/sequelize/issues/1944) - [BUG] Use the provided name for a unique index if one is given, instead of concating the column names together [#1944](https://github.com/sequelize/sequelize/issues/1944)
- [BUG] Create a composite primary key for doubled linked self reference [#1891](https://github.com/sequelize/sequelize/issues/1891)
- [INTERNALS] `bulkDeleteQuery` was removed from the MySQL / abstract query generator, since it was never used internally. Please use `deleteQuery` instead. - [INTERNALS] `bulkDeleteQuery` was removed from the MySQL / abstract query generator, since it was never used internally. Please use `deleteQuery` instead.
......
...@@ -151,9 +151,8 @@ module.exports = (function() { ...@@ -151,9 +151,8 @@ module.exports = (function() {
// or in an extra table which connects two tables // or in an extra table which connects two tables
HasMany.prototype.injectAttributes = function() { HasMany.prototype.injectAttributes = function() {
var doubleLinked = this.doubleLinked var doubleLinked = this.doubleLinked
, self = this , self = this;
, primaryKeyDeleted = false;
this.identifier = this.foreignKey || Utils._.camelizeIf( this.identifier = this.foreignKey || Utils._.camelizeIf(
[ [
Utils._.underscoredIf(Utils.singularize(this.source.name, this.source.options.language), this.source.options.underscored), Utils._.underscoredIf(Utils.singularize(this.source.name, this.source.options.language), this.source.options.underscored),
...@@ -199,7 +198,7 @@ module.exports = (function() { ...@@ -199,7 +198,7 @@ module.exports = (function() {
Utils._.each(this.through.rawAttributes, function(attribute, attributeName) { Utils._.each(this.through.rawAttributes, function(attribute, attributeName) {
if (attribute.primaryKey === true && attribute._autoGenerated === true) { if (attribute.primaryKey === true && attribute._autoGenerated === true) {
delete self.through.rawAttributes[attributeName]; delete self.through.rawAttributes[attributeName];
primaryKeyDeleted = true; self.targetAssociation.primaryKeyDeleted = true;
} }
}); });
...@@ -222,7 +221,7 @@ module.exports = (function() { ...@@ -222,7 +221,7 @@ module.exports = (function() {
targetAttribute.onUpdate = this.targetAssociation.options.onUpdate || 'CASCADE'; targetAttribute.onUpdate = this.targetAssociation.options.onUpdate || 'CASCADE';
} }
if (primaryKeyDeleted) { if (this.targetAssociation.primaryKeyDeleted === true) {
targetAttribute.primaryKey = sourceAttribute.primaryKey = true; targetAttribute.primaryKey = sourceAttribute.primaryKey = true;
} else { } else {
var uniqueKey = [this.through.tableName, this.identifier, this.foreignIdentifier, 'unique'].join('_'); var uniqueKey = [this.through.tableName, this.identifier, this.foreignIdentifier, 'unique'].join('_');
......
...@@ -1377,7 +1377,6 @@ module.exports = (function() { ...@@ -1377,7 +1377,6 @@ module.exports = (function() {
// We want to skip validations for all other fields // We want to skip validations for all other fields
var skippedFields = Utils._.difference(Object.keys(self.attributes), Object.keys(attrValueHash)); var skippedFields = Utils._.difference(Object.keys(self.attributes), Object.keys(attrValueHash));
return build.hookValidate({skip: skippedFields}).then(function(attributes) { return build.hookValidate({skip: skippedFields}).then(function(attributes) {
if (attributes && attributes.dataValues) { if (attributes && attributes.dataValues) {
attrValueHash = Utils._.pick(attributes.dataValues, Object.keys(attrValueHash)); attrValueHash = Utils._.pick(attributes.dataValues, Object.keys(attrValueHash));
......
This diff could not be displayed because it is too large.
...@@ -41,9 +41,17 @@ var Support = { ...@@ -41,9 +41,17 @@ var Support = {
var options = Sequelize.Utils._.extend({}, sequelize.options, { storage: path.join(__dirname, 'tmp', 'db.sqlite') }) var options = Sequelize.Utils._.extend({}, sequelize.options, { storage: path.join(__dirname, 'tmp', 'db.sqlite') })
, _sequelize = new Sequelize(sequelize.config.database, null, null, options); , _sequelize = new Sequelize(sequelize.config.database, null, null, options);
_sequelize.sync({ force: true }).success(function() { callback(_sequelize); }); if (callback) {
_sequelize.sync({ force: true }).success(function() { callback(_sequelize); });
} else {
return _sequelize.sync({ force: true }).return(_sequelize);
}
} else { } else {
callback(sequelize); if (callback) {
callback(sequelize);
} else {
return Sequelize.Promise.resolve(sequelize);
}
} }
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!