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

Commit 77c55541 by Sascha Depold

addAttribute is public

1 parent 82719d59
Showing with 8 additions and 10 deletions
...@@ -121,7 +121,6 @@ ModelFactory.prototype.build = function(values, options) { ...@@ -121,7 +121,6 @@ ModelFactory.prototype.build = function(values, options) {
options = options || {} options = options || {}
instance.__definition = this instance.__definition = this
//console.log(this.attributes)
Utils._.map(this.attributes, function(definition, name) { Utils._.map(this.attributes, function(definition, name) {
if(typeof instance[name] == 'undefined') { if(typeof instance[name] == 'undefined') {
var value = null var value = null
...@@ -130,7 +129,7 @@ ModelFactory.prototype.build = function(values, options) { ...@@ -130,7 +129,7 @@ ModelFactory.prototype.build = function(values, options) {
value = self.rawAttributes[name].defaultValue value = self.rawAttributes[name].defaultValue
instance[name] = value instance[name] = value
instance.__addAttribute(name, value) instance.addAttribute(name, value)
} }
}) })
Utils._.each(this.options.instanceMethods || {}, function(fct, name) { instance[name] = fct }) Utils._.each(this.options.instanceMethods || {}, function(fct, name) { instance[name] = fct })
......
...@@ -141,13 +141,18 @@ module.exports = (function() { ...@@ -141,13 +141,18 @@ module.exports = (function() {
return result return result
} }
Model.prototype.addAttribute = function(attribute, value) {
this[attribute] = value
this.attributes.push(attribute)
}
// private // private
var initAttributes = function(values) { var initAttributes = function(values) {
var self = this var self = this
// add all passed values to the model and store the attribute names in this.attributes // add all passed values to the model and store the attribute names in this.attributes
Utils._.map(values, function(value, key) { self.__addAttribute(key, value) }) Utils._.map(values, function(value, key) { self.addAttribute(key, value) })
// set id to null if not passed as value // set id to null if not passed as value
// a newly created model has no id // a newly created model has no id
...@@ -163,7 +168,7 @@ module.exports = (function() { ...@@ -163,7 +168,7 @@ module.exports = (function() {
Utils._.map(defaults, function(value, attr) { Utils._.map(defaults, function(value, attr) {
if(!self.hasOwnProperty(attr)) if(!self.hasOwnProperty(attr))
self.__addAttribute(attr, value) self.addAttribute(attr, value)
}) })
} }
...@@ -175,12 +180,6 @@ module.exports = (function() { ...@@ -175,12 +180,6 @@ module.exports = (function() {
return s.query.apply(s, args) return s.query.apply(s, args)
} }
Model.prototype.__addAttribute = function(attribute, value) {
this[attribute] = value
this.attributes.push(attribute)
}
/* Add the instance methods to Model */ /* Add the instance methods to Model */
Utils._.extend(Model.prototype, Mixin.prototype) Utils._.extend(Model.prototype, Mixin.prototype)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!