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

Commit 77dbbad1 by Sascha Depold

some factory changes

1 parent 5162c970
Showing with 19 additions and 2 deletions
module.exports.Factory = function(Sequelize, sequelize) { module.exports.Factory = function(Sequelize, sequelize) {
return { var Factory = {
addManyToManyMethods: function(table1, table2, assocName, backAssocName) {
table1.prototype[Sequelize.Helper.SQL.addPrefix('get', assocName)] = Factory.createManyToManyGetter(table1, table2, assocName, backAssocName)
table1.prototype[Sequelize.Helper.SQL.addPrefix('set', assocName)] = Factory.createManyToManySetter(table1, table2, assocName, backAssocName)
},
addOneToManyMethods: function(table1, table2, assocName, methodName) {
var setterName = Sequelize.Helper.SQL.addPrefix('set', methodName || assocName),
getterName = Sequelize.Helper.SQL.addPrefix('get', methodName || assocName)
table1.prototype[setterName] = Factory.createOneToManySetter(table1, assocName)
table1.prototype[getterName] = Factory.createOneToManyGetter(table1, table2, assocName)
return table1
},
createManyToManyGetter: function(table1, table2, assocName, backAssocName) { createManyToManyGetter: function(table1, table2, assocName, backAssocName) {
return function(callback) { return function(callback) {
var Association = sequelize.tables[Sequelize.Helper.SQL.manyToManyTableName(assocName, backAssocName)].klass, var Association = sequelize.tables[Sequelize.Helper.SQL.manyToManyTableName(assocName, backAssocName)].klass,
...@@ -73,7 +87,7 @@ module.exports.Factory = function(Sequelize, sequelize) { ...@@ -73,7 +87,7 @@ module.exports.Factory = function(Sequelize, sequelize) {
}) })
} }
}, },
createOneToManyGetter: function(table1, table2, assocName) { createOneToManyGetter: function(table1, table2, assocName) {
return function(callback) { return function(callback) {
var whereConditions = [Sequelize.Helper.SQL.asTableIdentifier(assocName), this.id].join("=") var whereConditions = [Sequelize.Helper.SQL.asTableIdentifier(assocName), this.id].join("=")
table2.findAll({where: whereConditions}, callback) table2.findAll({where: whereConditions}, callback)
...@@ -109,4 +123,6 @@ module.exports.Factory = function(Sequelize, sequelize) { ...@@ -109,4 +123,6 @@ module.exports.Factory = function(Sequelize, sequelize) {
} }
} }
} }
return Factory
} }
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!