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

Commit 4a717db1 by Sascha Depold

minor bugfixing + some refactoring

1 parent ab9055fa
......@@ -48,28 +48,25 @@ var classMethods = {
}
}
var instanceMethods = {
asTableName: function(name) {
return name + "s"
Sequelize.prototype = {
get tableNames() {
var result = []
SequelizeHelper.Hash.keys(this.tables).forEach(function(tableName) {
result.push(SequelizeHelper.SQL.asTableName(tableName))
})
return result
},
define: function(name, attributes) {
var table = new SequelizeTable(this, this.asTableName(name), attributes)
var table = new SequelizeTable(this, SequelizeHelper.SQL.asTableName(name), attributes)
table.attributes = attributes
this.tables[name] = {constructor: table, attributes: attributes}
table.sequelize = this
return table
},
get tableNames() {
var result = []
var self = this
SequelizeHelper.Hash.keys(this.tables).forEach(function(tableName) {
result.push(self.asTableName(tableName))
})
return result
},
query: function(queryString, callback) {
var fields = []
var values = []
......@@ -104,8 +101,4 @@ var instanceMethods = {
SequelizeHelper.Hash.forEach(classMethods, function(method, methodName) {
Sequelize[methodName] = method
})
SequelizeHelper.Hash.forEach(instanceMethods, function(method, methodName) {
Sequelize.prototype[methodName] = method
})
\ No newline at end of file
......@@ -5,6 +5,10 @@ SequelizeHelper = {
},
SQL: {
asTableName: function(name) {
return name + "s"
},
valuesForInsertQuery: function(object) {
var actualValues = object.values,
result = []
......
......@@ -63,19 +63,22 @@ SequelizeTable = function(sequelize, tableName, attributes) {
}
// instance methods
var instanceMethods = {
table.prototype = {
get values() {
var result = {}
var self = this
SequelizeHelper.Hash.keys(attributes).forEach(function(attribute) {
result[attribute] = self[attribute]
})
return result
},
save: function(callback) {
var query = null
var self = this
if(this.id == null)
query = Sequelize.sqlQueryFor('insert', {
table: this.tableName, fields: SequelizeHelper.SQL.fieldsForInsertQuery(this), values: SequelizeHelper.SQL.valuesForInsertQuery(this)
......@@ -86,7 +89,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
sequelize.query(query, function() {
if(self.id == null) {
table.find(self.values, function(result) {
SequelizeHelper.log(result)
self.id = result.id
if(callback) callback(self)
})
......@@ -116,10 +118,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
SequelizeHelper.Hash.forEach(classMethods, function(method, methodName) {
table[methodName] = method
})
SequelizeHelper.Hash.forEach(instanceMethods, function(method, methodName) {
table.prototype[methodName] = method
})
return table
}
\ 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!