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

Commit a46121ce by Mick Hansen

refactor a few things to support associations still ;)

1 parent 79c364db
......@@ -32,8 +32,8 @@ module.exports = (function() {
Helpers.addForeignKeyConstraints(newAttributes[this.identifier], this.target, this.source, this.options)
Utils._.defaults(this.source.rawAttributes, newAttributes)
// Sync attributes to DAO proto each time a new assoc is added
this.source.DAO.prototype.attributes = Object.keys(this.source.DAO.prototype.rawAttributes)
// Sync attributes and setters/getters to DAO prototype
this.source.refreshAttributes()
return this
}
......
......@@ -109,9 +109,9 @@ module.exports = (function() {
Utils._.defaults(this.target.rawAttributes, newAttributes)
}
// Sync attributes to DAO proto each time a new assoc is added
this.target.DAO.prototype.attributes = Object.keys(this.target.DAO.prototype.rawAttributes);
this.source.DAO.prototype.attributes = Object.keys(this.source.DAO.prototype.rawAttributes);
// Sync attributes and setters/getters to DAO prototype
this.target.refreshAttributes()
this.source.refreshAttributes()
return this
}
......
......@@ -37,9 +37,8 @@ module.exports = (function() {
Helpers.addForeignKeyConstraints(newAttributes[this.identifier], this.source, this.target, this.options)
Utils._.defaults(this.target.rawAttributes, newAttributes)
// Sync attributes to DAO proto each time a new assoc is added
this.target.DAO.prototype.attributes = Object.keys(this.target.DAO.prototype.rawAttributes);
// Sync attributes and setters/getters to DAO prototype
this.target.refreshAttributes()
return this
}
......
......@@ -141,7 +141,35 @@ module.exports = (function() {
})
}
var attributeManipulation = {};
this.refreshAttributes();
this.DAO.prototype.booleanValues = []
this.DAO.prototype.defaultValues = {}
this.DAO.prototype.validators = {}
Utils._.each(this.rawAttributes, function (definition, name) {
if (((definition === DataTypes.BOOLEAN) || (definition.type === DataTypes.BOOLEAN))) {
self.DAO.prototype.booleanValues.push(name);
}
if (definition.hasOwnProperty('defaultValue')) {
self.DAO.prototype.defaultValues[name] = Utils._.partial(
Utils.toDefaultValue, definition.defaultValue)
}
if (definition.hasOwnProperty('validate')) {
self.DAO.prototype.validators[name] = definition.validate;
}
})
this.DAO.prototype.__factory = this
this.DAO.prototype.hasDefaultValues = !Utils._.isEmpty(this.DAO.prototype.defaultValues)
return this
}
DAOFactory.prototype.refreshAttributes = function() {
var self = this
, attributeManipulation = {};
Utils._.each(['get', 'set'], function(type) {
var opt = type + 'terMethods'
......@@ -173,36 +201,17 @@ module.exports = (function() {
})
Utils._.each(funcs, function(fct, name) {
if (!attributeManipulation[name]) attributeManipulation[name] = {}
if (!attributeManipulation[name]) {
attributeManipulation[name] = {
configurable: true
}
}
attributeManipulation[name][type] = fct
})
})
Object.defineProperties(this.DAO.prototype, attributeManipulation)
this.DAO.prototype.attributes = Object.keys(this.DAO.prototype.rawAttributes);
this.DAO.prototype.booleanValues = []
this.DAO.prototype.defaultValues = {}
this.DAO.prototype.validators = {}
Utils._.each(this.rawAttributes, function (definition, name) {
if (((definition === DataTypes.BOOLEAN) || (definition.type === DataTypes.BOOLEAN))) {
self.DAO.prototype.booleanValues.push(name);
}
if (definition.hasOwnProperty('defaultValue')) {
self.DAO.prototype.defaultValues[name] = Utils._.partial(
Utils.toDefaultValue, definition.defaultValue)
}
if (definition.hasOwnProperty('validate')) {
self.DAO.prototype.validators[name] = definition.validate;
}
})
this.DAO.prototype.__factory = this
this.DAO.prototype.hasDefaultValues = !Utils._.isEmpty(this.DAO.prototype.defaultValues)
return this
this.DAO.prototype.attributes = Object.keys(this.DAO.prototype.rawAttributes)
}
DAOFactory.prototype.sync = function(options) {
......
......@@ -1953,7 +1953,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
this.User.find({ limit: 10 }).success(function(user) {
// it returns an object instead of an array
expect(Array.isArray(user)).to.not.be.ok
expect(user.hasOwnProperty('username')).to.be.ok
expect(user.dataValues.hasOwnProperty('username')).to.be.ok
done()
})
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!