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

Commit 9a9f2c18 by Jan Aagaard Meier

Fix a belongsTo + hasMany relation incorrectly being identified as n:m. Closes #2159

1 parent fe9fdc94
Showing with 5 additions and 5 deletions
......@@ -69,7 +69,7 @@ module.exports = (function() {
*/
else if (this.through) {
_.each(this.target.associations, function (association, accessor) {
if (self.source === association.target) {
if (self.source === association.target && association.associationType === 'HasMany') {
var paired = false
// If through is default, we determine pairing by the accesor value (i.e. DAOFactory's using as won't pair, but regular ones will)
......@@ -116,9 +116,9 @@ module.exports = (function() {
if (this.as) {
this.isAliased = true
} else {
this.as = (this.options.freezeAssociations ? this.target.tableName : Utils.pluralize(this.target.tableName, this.target.options.language));
this.as = (this.options.freezeAssociations ? this.target.tableName : Utils.pluralize(this.target.tableName, this.target.options.language));
}
this.accessors = {
get: Utils._.camelize('get_' + this.as),
set: Utils._.camelize('set_' + this.as),
......@@ -172,11 +172,11 @@ module.exports = (function() {
var sourceKeyType = ((!this.source.hasPrimaryKeys || sourceKeys.length !== 1) ? DataTypes.INTEGER : this.source.rawAttributes[sourceKeys[0]].type)
var targetKeys = Object.keys(this.target.primaryKeys);
var targetKeyType = ((!this.target.hasPrimaryKeys || targetKeys.length !== 1) ? DataTypes.INTEGER : this.target.rawAttributes[targetKeys[0]].type)
if (primaryKeyDeleted) {
combinedTableAttributes[this.identifier] = {type: sourceKeyType, primaryKey: true}
combinedTableAttributes[this.foreignIdentifier] = {type: targetKeyType, primaryKey: true}
} else {
} else {
var uniqueKey = [this.through.tableName, this.identifier, this.foreignIdentifier, 'unique'].join('_')
combinedTableAttributes[this.identifier] = {type: sourceKeyType, unique: uniqueKey}
combinedTableAttributes[this.foreignIdentifier] = {type: targetKeyType, unique: uniqueKey}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!