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

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() {
var newAttributes = {}
this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.source.tableName) + "Id", this.options.underscored)
newAttributes[this.identifier] = { type: DataTypes.INTEGER }
Utils._.extend(this.target.rawAttributes, newAttributes)
return this
}
HasOne.prototype.injectGetter = function(obj) {
var self = this
, where = {}
where[self.identifier] = id
obj[this.accessors.get] = function() {
var id = obj.id
, where = {}
where[self.identifier] = id
return self.target.find({where: where})
}
return this
}
......@@ -50,11 +53,11 @@ module.exports = (function() {
var customEventEmitter = new Utils.CustomEventEmitter(function() {
obj[self.accessors.get]().success(function(oldObj) {
if(oldObj) {
oldObj = Utils.setAttributes(oldObj, self.identifier, self.options.omitNull ? '' : null)
oldObj[self.identifier] = self.options.omitNull ? '' : null;
oldObj.save()
}
associatedObject = Utils.setAttributes(associatedObject, self.identifier, obj)
associatedObject[self.identifier] = obj.id
associatedObject.save()
.success(function() { customEventEmitter.emit('success', associatedObject) })
.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!