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

Commit f99845b6 by Mick Hansen

Refactor

1 parent 78bb1a2a
Showing with 19 additions and 13 deletions
......@@ -203,17 +203,19 @@ module.exports = (function() {
this.refreshAttributes();
this.DAO.prototype.booleanValues = []
this.DAO.prototype.dateAttributes = []
this._booleanAttributes = []
this._dateAttributes = []
this.DAO.prototype.booleanValues = this._booleanAttributes
this.DAO.prototype.dateAttributes = this._dateAttributes
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);
self._booleanAttributes.push(name);
}
if (((definition === DataTypes.DATE) || (definition.type === DataTypes.DATE) || (definition.originalType === DataTypes.DATE))) {
self.DAO.prototype.dateAttributes.push(name);
self._dateAttributes.push(name);
}
if (definition.hasOwnProperty('defaultValue')) {
self.DAO.prototype.defaultValues[name] = Utils._.partial(
......@@ -225,15 +227,19 @@ module.exports = (function() {
}
})
this.DAO.prototype._hasBooleanAttributes = !!this.DAO.prototype.booleanValues.length
this.DAO.prototype._isBooleanAttribute = Utils._.memoize(function (key) {
return self.DAO.prototype.booleanValues.indexOf(key) !== -1
this._hasBooleanAttributes = !!this._booleanAttributes.length
this._isBooleanAttribute = Utils._.memoize(function (key) {
return self._booleanAttributes.indexOf(key) !== -1
})
this.DAO.prototype._hasBooleanAttributes = this._hasBooleanAttributes
this.DAO.prototype._isBooleanAttribute = this._isBooleanAttribute
this.DAO.prototype._hasDateAttributes = !!this.DAO.prototype.dateAttributes.length
this.DAO.prototype._isDateAttribute = Utils._.memoize(function (key) {
return self.DAO.prototype.dateAttributes.indexOf(key) !== -1
this._hasDateAttributes = !!this._dateAttributes.length
this._isDateAttribute = Utils._.memoize(function (key) {
return self._dateAttributes.indexOf(key) !== -1
})
this.DAO.prototype._hasDateAttributes = this._hasDateAttributes
this.DAO.prototype._isDateAttribute = this._isDateAttribute
this.DAO.prototype.__factory = this
this.DAO.prototype.daoFactory = this
......
......@@ -123,7 +123,7 @@ module.exports = (function() {
}
// If raw, and we're not dealing with includes, just set it straight on the dataValues object
if (options.raw && !(this.options && this.options.include) && !this._hasBooleanAttributes) {
if (options.raw && !(this.options && this.options.include) && !this.Model._hasBooleanAttributes) {
if (Object.keys(this.dataValues).length) {
this.dataValues = _.extend(this.dataValues, values)
} else {
......@@ -188,7 +188,7 @@ module.exports = (function() {
DAO.prototype.changed = function(key) {
if (key) {
if (this._isDateAttribute(key) && this._previousDataValues[key] && this.dataValues[key]) {
if (this.Model._isDateAttribute(key) && this._previousDataValues[key] && this.dataValues[key]) {
return this._previousDataValues[key].valueOf() !== this.dataValues[key].valueOf()
}
return this._previousDataValues[key] !== this.dataValues[key]
......@@ -356,7 +356,7 @@ module.exports = (function() {
args = [self, self.QueryInterface.QueryGenerator.addSchema(self.Model), values, options]
hook = 'Create'
} else {
var identifier = self.__options.hasPrimaryKeys ? self.primaryKeyValues : { id: self.id }
var identifier = self.primaryKeyValues
if (identifier === null && self.__options.whereCollection !== null) {
identifier = self.__options.whereCollection;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!