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

Commit f5c504a6 by Sascha Depold

refactoring + methodName fixing

1 parent bd0c8c63
Showing with 10 additions and 8 deletions
...@@ -155,21 +155,23 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o ...@@ -155,21 +155,23 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
return association return association
}, },
hasMany: function(assocName, associateWith, backAssocName) { hasMany: function(assocName, associationTable, backAssocName) {
if(typeof assocName == 'undefined') if(typeof assocName == 'undefined')
throw new Error('Please specify at least an association name!') throw new Error('Please specify at least an association name!')
if(associateWith) { if(associationTable) {
var Factory = new require("./Factory").Factory(Sequelize, sequelize), var Factory = new require("./Factory").Factory(Sequelize, sequelize),
association = { name: assocName, backAssociationName: backAssocName, table: associateWith, type: 'hasMany' } association = { name: assocName, backAssociationName: backAssocName, table: associationTable, type: 'hasMany' },
backAssociation = { name: backAssocName, backAssociationName: assocName, table: table, type: 'hasMany' }
table.associations.push(association) table.associations.push(association)
if(backAssocName) { if(backAssocName) {
Factory.addManyToManyMethods(table, associateWith, assocName, backAssocName) associationTable.associations.push(backAssociation)
Factory.addManyToManyMethods(associateWith, table, backAssocName, assocName) Factory.addManyToManyMethods(table, associationTable, assocName, backAssocName)
Factory.addManyToManyMethods(associationTable, table, backAssocName, assocName)
} else { } else {
Factory.addOneToManyMethods(table, associateWith, assocName) Factory.addOneToManyMethods(table, associationTable, assocName)
} }
return association return association
...@@ -221,7 +223,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o ...@@ -221,7 +223,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
table.associations.push({ name: assocName, table: _table, type: 'belongsTo' }) table.associations.push({ name: assocName, table: _table, type: 'belongsTo' })
// getter // 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) var identifier = Sequelize.Helper.SQL.asTableIdentifier(assocName)
if((this[identifier] == null)||(isNaN(this[identifier]))) callback([]) if((this[identifier] == null)||(isNaN(this[identifier]))) callback([])
...@@ -236,7 +238,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o ...@@ -236,7 +238,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
attr[Sequelize.Helper.SQL.asTableIdentifier(assocName)] = object.id attr[Sequelize.Helper.SQL.asTableIdentifier(assocName)] = object.id
this.updateAttributes(attr, function() { 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!