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

Commit 45fce2bf by Jan Aagaard Meier

assocations

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