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

Commit 45fce2bf by Jan Aagaard Meier

assocations

1 parent c77c2bc3
...@@ -33,7 +33,7 @@ module.exports = (function() { ...@@ -33,7 +33,7 @@ module.exports = (function() {
, accessor = Utils._.camelize('get_' + (this.options.as || Utils.singularize(this.target.tableName))) , accessor = Utils._.camelize('get_' + (this.options.as || Utils.singularize(this.target.tableName)))
obj[accessor] = function() { obj[accessor] = function() {
var id = obj[self.identifier] var id = this[self.identifier]
return self.target.find(id) return self.target.find(id)
} }
...@@ -45,10 +45,10 @@ module.exports = (function() { ...@@ -45,10 +45,10 @@ module.exports = (function() {
, accessor = Utils._.camelize('set_' + (this.options.as || Utils.singularize(this.target.tableName))) , accessor = Utils._.camelize('set_' + (this.options.as || Utils.singularize(this.target.tableName)))
obj[accessor] = function(associatedObject) { obj[accessor] = function(associatedObject) {
obj[self.identifier] = associatedObject ? associatedObject.id : null this[self.identifier] = associatedObject ? associatedObject.id : null
// passes the changed field to save, so only that field get updated. // passes the changed field to save, so only that field get updated.
return obj.save([ self.identifier ]) return this.save([ self.identifier ])
} }
return this return this
......
...@@ -53,15 +53,16 @@ module.exports = (function() { ...@@ -53,15 +53,16 @@ module.exports = (function() {
, options = self.options || {} , options = self.options || {}
obj[this.accessors.set] = function(associatedObject) { obj[this.accessors.set] = function(associatedObject) {
var instance = this;
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
obj[self.accessors.get]().success(function(oldObj) { instance[self.accessors.get]().success(function(oldObj) {
if(oldObj) { if(oldObj) {
oldObj[self.identifier] = null oldObj[self.identifier] = null
oldObj.save() oldObj.save()
} }
if(associatedObject) { if(associatedObject) {
associatedObject[self.identifier] = obj.id associatedObject[self.identifier] = instance.id
associatedObject associatedObject
.save() .save()
.success(function() { emitter.emit('success', associatedObject) }) .success(function() { emitter.emit('success', associatedObject) })
......
...@@ -27,11 +27,8 @@ module.exports = (function() { ...@@ -27,11 +27,8 @@ module.exports = (function() {
// extract validation // extract validation
this.validate = this.options.validate || {} this.validate = this.options.validate || {}
// DAO prototype // DAO prototype
this.DAO = function(values, options) { this.DAO = function() {
DAO.apply(this, arguments); DAO.apply(this, arguments);
}; };
Util.inherits(this.DAO, DAO); Util.inherits(this.DAO, DAO);
...@@ -229,10 +226,6 @@ module.exports = (function() { ...@@ -229,10 +226,6 @@ module.exports = (function() {
}) })
Utils._.each(this.options.instanceMethods || {}, function(fct, name) { instance[name] = fct }) Utils._.each(this.options.instanceMethods || {}, function(fct, name) { instance[name] = fct })
// Utils._.each(this.associations, function(association) {
// association.injectGetter(instance)
// association.injectSetter(instance)
// })
instance.isNewRecord = options.hasOwnProperty('isNewRecord') ? options.isNewRecord : true instance.isNewRecord = options.hasOwnProperty('isNewRecord') ? options.isNewRecord : true
instance.selectedValues = values instance.selectedValues = values
......
...@@ -285,8 +285,5 @@ module.exports = (function() { ...@@ -285,8 +285,5 @@ module.exports = (function() {
} }
} }
/* Add the instance methods to DAO */
Utils._.extend(DAO.prototype, Mixin.prototype)
return DAO return DAO
})() })()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!