Skip to content

Instantly share code, notes, and snippets.

@mickhansen
Created March 18, 2014 16:55
Show Gist options
  • Save mickhansen/9624269 to your computer and use it in GitHub Desktop.
Save mickhansen/9624269 to your computer and use it in GitHub Desktop.
var Sequelize = require('sequelize'),
DAO = require('sequelize/lib/dao'),
_increment = DAO.prototype.increment,
_decrement = DAO.prototype.decrement;
DAO.prototype.increment = function(field, options) {
var instance = this,
by = (options && options.by) || options || 1;
instance.set(field, instance.get(field) + by);
return (_increment.apply(instance, arguments)).success(function () {
if (by > 0) {
instance.Model.runHooks('afterIncrement', instance, {field: field, by: by}, function () {
});
} else {
instance.Model.runHooks('afterDecrement', instance, {field: field, by: by}, function () {
});
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment