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

Commit 47bc7007 by Sascha Depold

assoc setter for belongsTo and hasOne

1 parent e6c57ea9
Showing with 21 additions and 0 deletions
...@@ -236,6 +236,22 @@ SequelizeTable = function(sequelize, tableName, attributes) { ...@@ -236,6 +236,22 @@ SequelizeTable = function(sequelize, tableName, attributes) {
_table.find(whereConditions, callback) _table.find(whereConditions, callback)
} }
table.prototype[SequelizeHelper.SQL.addPrefix('set', assocName)] = function(object, callback) {
var self = this
this[assocName](function(currentAssociation) {
if(object.id == currentAssociation.id) callback()
else {
var attr = {}
attr[table.identifier] = null
currentAssociation.updateAttributes(attr, function() {
attr[table.identifier] = self.id
object.updateAttributes(attr, callback)
})
}
})
}
return table return table
}, },
...@@ -251,6 +267,11 @@ SequelizeTable = function(sequelize, tableName, attributes) { ...@@ -251,6 +267,11 @@ SequelizeTable = function(sequelize, tableName, attributes) {
_table.find({where: whereConditions}, callback) _table.find({where: whereConditions}, callback)
} }
table.prototype[SequelizeHelper.SQL.addPrefix('set', assocName)] = function(object, callback) {
var attr = {}; attr[object.table.identifier] = object.id
this.updateAttributes(attr, callback)
}
return table return table
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!