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

Commit 6f898d85 by Mick Hansen

Merge branch 'master' of https://github.com/quiddle/sequelize into quiddle-master

2 parents 75304090 bc0cca4e
Showing with 23 additions and 1 deletions
......@@ -840,11 +840,25 @@ module.exports = (function() {
deprecationWarning: 'Increment expects an object as second parameter. Please pass the incrementor as option! ~> instance.increment(' + JSON.stringify(fields) + ', { by: ' + countOrOptions + ' })'
});
var identifier = this.__options.hasPrimaryKeys ? this.primaryKeyValues : { id: this.id }
var identifier = this.primaryKeyValues
, updatedAtAttr = this.Model._timestampAttributes.updatedAt
, values = {}
, where;
if (identifier) {
for (var attrName in identifier) {
// Field name mapping
var rawAttribute = this.Model.rawAttributes[attrName];
if (rawAttribute.field && rawAttribute.field !== rawAttribute.fieldName) {
identifier[this.Model.rawAttributes[attrName].field] = identifier[attrName];
delete identifier[attrName];
}
}
}
if (identifier === null && this.__options.whereCollection !== null) {
identifier = this.__options.whereCollection;
}
if (countOrOptions === undefined) {
countOrOptions = { by: 1 };
} else if (typeof countOrOptions === 'number') {
......@@ -873,6 +887,14 @@ module.exports = (function() {
countOrOptions.attributes[updatedAtAttr] = this.Model.__getTimestamp(updatedAtAttr);
}
Object.keys(values).forEach(function(attr) {
// Field name mapping
if (this.Model.rawAttributes[attr] && this.Model.rawAttributes[attr].field && this.Model.rawAttributes[attr].field !== attr) {
values[this.Model.rawAttributes[attr].field] = values[attr];
delete values[attr];
}
}, this);
return this.QueryInterface.increment(this, this.Model.getTableName(countOrOptions), values, where, countOrOptions);
};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!