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

Commit 5b0d6497 by Sascha Depold

renamed didChange to hasChanged

1 parent 03137ae8
Showing with 9 additions and 6 deletions
......@@ -87,7 +87,7 @@ module.exports = (function() {
DAO.prototype.get = DAO.prototype.getDataValue
DAO.prototype.setDataValue = function(name, value) {
if (Utils.didChange(this.dataValues[name], value)) {
if (Utils.hasChanged(this.dataValues[name], value)) {
this.isDirty = true
}
this.dataValues[name] = value
......@@ -240,7 +240,7 @@ module.exports = (function() {
(self.attributes.indexOf(attr) > -1)
)
if (updateAllowed) {
if (Utils.didChange(self[attr], value)) {
if (Utils.hasChanged(self[attr], value)) {
isDirty = true
}
self[attr] = value
......@@ -346,7 +346,7 @@ module.exports = (function() {
if (has !== true) {
this.__defineGetter__(attribute, has.get || function() { return this.dataValues[attribute]; });
this.__defineSetter__(attribute, has.set || function(v) {
if (Utils.didChange(this.dataValues[attribute], v)) {
if (Utils.hasChanged(this.dataValues[attribute], v)) {
//Only dirty the object if the change is not due to id, touchedAt, createdAt or updatedAt being initiated
var updatedAtAttr = this.__options.underscored ? 'updated_at' : 'updatedAt'
, createdAtAttr = this.__options.underscored ? 'created_at' : 'createdAt'
......
......@@ -252,18 +252,21 @@ var Utils = module.exports = {
isHash: function(obj) {
return Utils._.isObject(obj) && !Array.isArray(obj);
},
didChange: function(attrValue, value) {
hasChanged: function(attrValue, value) {
//If attribute value is Date, check value as a date
if (Utils._.isDate(attrValue) && !Utils._.isDate(value)) {
value = new Date(value)
}
if (Utils._.isDate(attrValue)) {
return attrValue.valueOf() !== value.valueOf()
return attrValue.valueOf() !== value.valueOf()
}
//If both of them are empty, don't set as changed
if ((attrValue === undefined || attrValue === null || attrValue === '') && (value === undefined || value === null || value === '')) {
return false
return false
}
return attrValue !== value
},
argsArePrimaryKeys: function(args, primaryKeys) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!