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

Commit f5c504a6 by Sascha Depold

refactoring + methodName fixing

1 parent bd0c8c63
Showing with 11 additions and 9 deletions
......@@ -155,21 +155,23 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
return association
},
hasMany: function(assocName, associateWith, backAssocName) {
hasMany: function(assocName, associationTable, backAssocName) {
if(typeof assocName == 'undefined')
throw new Error('Please specify at least an association name!')
if(associateWith) {
var Factory = new require("./Factory").Factory(Sequelize, sequelize),
association = { name: assocName, backAssociationName: backAssocName, table: associateWith, type: 'hasMany' }
if(associationTable) {
var Factory = new require("./Factory").Factory(Sequelize, sequelize),
association = { name: assocName, backAssociationName: backAssocName, table: associationTable, type: 'hasMany' },
backAssociation = { name: backAssocName, backAssociationName: assocName, table: table, type: 'hasMany' }
table.associations.push(association)
if(backAssocName) {
Factory.addManyToManyMethods(table, associateWith, assocName, backAssocName)
Factory.addManyToManyMethods(associateWith, table, backAssocName, assocName)
associationTable.associations.push(backAssociation)
Factory.addManyToManyMethods(table, associationTable, assocName, backAssocName)
Factory.addManyToManyMethods(associationTable, table, backAssocName, assocName)
} else {
Factory.addOneToManyMethods(table, associateWith, assocName)
Factory.addOneToManyMethods(table, associationTable, assocName)
}
return association
......@@ -221,7 +223,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
table.associations.push({ name: assocName, table: _table, type: 'belongsTo' })
// getter
table.prototype[Sequelize.Helper.SQL.addPrefix('get', assocName)] = function(callback) {
table.prototype[Sequelize.Helper.SQL.addPrefix('get', assocName, true)] = function(callback) {
var identifier = Sequelize.Helper.SQL.asTableIdentifier(assocName)
if((this[identifier] == null)||(isNaN(this[identifier]))) callback([])
......@@ -236,7 +238,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
attr[Sequelize.Helper.SQL.asTableIdentifier(assocName)] = object.id
this.updateAttributes(attr, function() {
self[Sequelize.Helper.SQL.addPrefix('get', assocName)](callback)
self[Sequelize.Helper.SQL.addPrefix('get', assocName, true)](callback)
})
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!