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

Commit 3a6b4f55 by Sascha Depold

use the assocname as table identifier

1 parent 354c88ee
Showing with 6 additions and 4 deletions
......@@ -46,26 +46,28 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
prepareAssociations: function(callback) {
table.associations.forEach(function(association) {
var assocNameAsTableIdentifier = Sequelize.Helper.SQL.asTableIdentifier(association.name)
switch(association.type) {
case 'hasMany':
if(association.backAssociationName) {
// many to many relation
var _attributes = {}
_attributes[Sequelize.Helper.SQL.asTableIdentifier(association.name)] = Sequelize.INTEGER
_attributes[assocNameAsTableIdentifier] = Sequelize.INTEGER
_attributes[Sequelize.Helper.SQL.asTableIdentifier(association.backAssociationName)] = Sequelize.INTEGER
sequelize.define(Sequelize.Helper.SQL.manyToManyTableName(association.name, association.backAssociationName), _attributes)
} else {
// one to many relation
association.table.attributes[table.identifier] = {type: Sequelize.INTEGER}
association.table.attributes[assocNameAsTableIdentifier] = {type: Sequelize.INTEGER}
}
break
case 'hasOne':
// e.g. assocTable.myTableId = Sequelize.INTEGER
association.table.attributes[table.identifier] = {type: Sequelize.INTEGER}
association.table.attributes[assocNameAsTableIdentifier] = {type: Sequelize.INTEGER}
break
case 'belongsTo':
// e.g. table.dayId = Sequelize.INTEGER
table.attributes[association.table.identifier] = {type :Sequelize.INTEGER}
table.attributes[assocNameAsTableIdentifier] = {type :Sequelize.INTEGER}
break
}
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!