Skip to content

Commit

Permalink
Join columns now have correct default type based upon association PK …
Browse files Browse the repository at this point in the history
…type

Default was integer, which led to casting errors returning the incorrect data
  • Loading branch information
lemon-tree committed Aug 29, 2013
1 parent f3317cd commit 9c35735
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/associations/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ module.exports = (function() {
var newAttributes = {}

this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.target.tableName, this.target.options.language) + "Id", this.source.options.underscored)
newAttributes[this.identifier] = { type: this.options.keyType || DataTypes.INTEGER }
var targetKeys = Object.keys(this.target.primaryKeys)
var keyType = ((this.target.hasPrimaryKeys && targetKeys.length === 1) ? this.target.rawAttributes[targetKeys[0]].type : DataTypes.INTEGER)
newAttributes[this.identifier] = { type: this.options.keyType ||keyType }
Helpers.addForeignKeyConstraints(newAttributes[this.identifier], this.target, this.source, this.options)
Utils._.defaults(this.source.rawAttributes, newAttributes)

Expand Down
4 changes: 3 additions & 1 deletion lib/associations/has-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ module.exports = (function() {
var newAttributes = {}

this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.source.tableName, this.source.options.language) + "Id", this.options.underscored)
newAttributes[this.identifier] = { type: this.options.keyType || DataTypes.INTEGER }
var sourceKeys = Object.keys(this.source.primaryKeys)
var keyType = ((this.source.hasPrimaryKeys && sourceKeys.length === 1) ? this.source.rawAttributes[sourceKeys[0]].type : DataTypes.INTEGER)
newAttributes[this.identifier] = { type: this.options.keyType || keyType }
Helpers.addForeignKeyConstraints(newAttributes[this.identifier], this.source, this.target, this.options)
Utils._.defaults(this.target.rawAttributes, newAttributes)

Expand Down

0 comments on commit 9c35735

Please sign in to comment.