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

Commit 8a262be3 by Jan Aagaard Meier

cleaning up

1 parent 1bdf42dd
Showing with 11 additions and 8 deletions
...@@ -26,19 +26,22 @@ module.exports = (function() { ...@@ -26,19 +26,22 @@ module.exports = (function() {
var newAttributes = {} var newAttributes = {}
this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.source.tableName) + "Id", this.options.underscored) this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.source.tableName) + "Id", this.options.underscored)
newAttributes[this.identifier] = { type: DataTypes.INTEGER } newAttributes[this.identifier] = { type: DataTypes.INTEGER }
Utils._.extend(this.target.rawAttributes, newAttributes) Utils._.extend(this.target.rawAttributes, newAttributes)
return this return this
} }
HasOne.prototype.injectGetter = function(obj) { HasOne.prototype.injectGetter = function(obj) {
var self = this var self = this
, where = {}
obj[this.accessors.get] = function() {
where[self.identifier] = id var id = obj.id
, where = {}
where[self.identifier] = id
return self.target.find({where: where})
}
return this return this
} }
...@@ -50,11 +53,11 @@ module.exports = (function() { ...@@ -50,11 +53,11 @@ module.exports = (function() {
var customEventEmitter = new Utils.CustomEventEmitter(function() { var customEventEmitter = new Utils.CustomEventEmitter(function() {
obj[self.accessors.get]().success(function(oldObj) { obj[self.accessors.get]().success(function(oldObj) {
if(oldObj) { if(oldObj) {
oldObj = Utils.setAttributes(oldObj, self.identifier, self.options.omitNull ? '' : null) oldObj[self.identifier] = self.options.omitNull ? '' : null;
oldObj.save() oldObj.save()
} }
associatedObject = Utils.setAttributes(associatedObject, self.identifier, obj) associatedObject[self.identifier] = obj.id
associatedObject.save() associatedObject.save()
.success(function() { customEventEmitter.emit('success', associatedObject) }) .success(function() { customEventEmitter.emit('success', associatedObject) })
.error(function(err) { customEventEmitter.emit('failure', err) }) .error(function(err) { customEventEmitter.emit('failure', err) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!