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

Commit a86e1308 by Sascha Depold

added updateAttributes

1 parent 68a93410
Showing with 10 additions and 1 deletions
...@@ -159,7 +159,7 @@ var TableWrapper = function(sequelize, tableName, attributes) { ...@@ -159,7 +159,7 @@ var TableWrapper = function(sequelize, tableName, attributes) {
{ table: this.tableName, fields: Helper.SQL.fieldsForInsertQuery(this), values: Helper.SQL.valuesForInsertQuery(this) } { table: this.tableName, fields: Helper.SQL.fieldsForInsertQuery(this), values: Helper.SQL.valuesForInsertQuery(this) }
) )
} else { } else {
query = evaluateTemplate( query = Helper.evaluateTemplate(
"UPDATE %{table} SET %{values} WHERE id = %{id}", "UPDATE %{table} SET %{values} WHERE id = %{id}",
{ table: this.tableName, values: Helper.SQL.valuesForUpdate(this), id: this.id } { table: this.tableName, values: Helper.SQL.valuesForUpdate(this), id: this.id }
) )
...@@ -176,6 +176,15 @@ var TableWrapper = function(sequelize, tableName, attributes) { ...@@ -176,6 +176,15 @@ var TableWrapper = function(sequelize, tableName, attributes) {
if(callback) callback(self) if(callback) callback(self)
} }
}) })
},
updateAttributes: function(newValues, callback) {
var self = this
Helper.Hash.keys(this.attributes).forEach(function(attribute) {
if(newValues[attribute])
self[attribute] = newValues[attribute]
})
this.save(callback)
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!