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

Commit e8f73c21 by Jan Aagaard Meier

Merge pull request #1544 from seegno/fix-fk-type-inference

Fix foreign key type inference
2 parents 70a0cb3e 71068a11
...@@ -209,7 +209,7 @@ module.exports = (function() { ...@@ -209,7 +209,7 @@ module.exports = (function() {
} else { } else {
var newAttributes = {} var newAttributes = {}
var constraintOptions = _.clone(this.options) // Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m var constraintOptions = _.clone(this.options) // Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m
newAttributes[this.identifier] = { type: this.options.keyType || this.target.rawAttributes[this.target.primaryKeyAttribute].type } newAttributes[this.identifier] = { type: this.options.keyType || this.source.rawAttributes[this.source.primaryKeyAttribute].type }
if (this.options.constraints !== false) { if (this.options.constraints !== false) {
constraintOptions.onDelete = constraintOptions.onDelete || 'SET NULL' constraintOptions.onDelete = constraintOptions.onDelete || 'SET NULL'
......
...@@ -1732,5 +1732,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1732,5 +1732,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}) })
}) })
}) })
it('infers the keyType if none provided', function(done) {
var User = this.sequelize.define('User', {
id: { type: DataTypes.STRING, primaryKey: true },
username: DataTypes.STRING
})
, Task = this.sequelize.define('Task', {
title: DataTypes.STRING
})
User.hasMany(Task)
this.sequelize.sync({ force: true }).success(function() {
expect(Task.rawAttributes.UserId.type)
.to.equal(DataTypes.STRING)
done()
})
})
}) })
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!