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

Commit b9a9ef20 by Gabe Gorelick Committed by Sushant

feat(increment): support scopes (#8541)

1 parent 089504fe
......@@ -86,7 +86,7 @@ DeletedProjects.findAll();
DeletedProjects.findAll();
```
Scopes apply to `.find`, `.findAll`, `.count`, `.update` and `.destroy`.
Scopes apply to `.find`, `.findAll`, `.count`, `.update`, `.increment` and `.destroy`.
Scopes which are functions can be invoked in two ways. If the scope does not take any arguments it can be invoked as normally. If the scope takes arguments, pass an object:
......
......@@ -2892,6 +2892,8 @@ class Model {
* @return {Promise<this>}
*/
static increment(fields, options) {
options = options || {};
this._injectScope(options);
this._optionsMustContainWhere(options);
const updatedAtAttr = this._timestampAttributes.updatedAt;
......
......@@ -2931,5 +2931,48 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return expect(User.findById(1)).to.eventually.have.property('updatedAt').equalTime(oldDate);
});
});
it('should work with scopes', function() {
const User = this.sequelize.define('User', {
aNumber: DataTypes.INTEGER,
name: DataTypes.STRING
}, {
scopes: {
jeff: {
where: {
name: 'Jeff'
}
}
}
});
return User.sync({ force: true }).then(() => {
return User.bulkCreate([
{
aNumber: 1,
name: 'Jeff'
},
{
aNumber: 3,
name: 'Not Jeff'
}
]);
}).then(() => {
return User.scope('jeff').increment('aNumber', {
});
}).then(() => {
return User.scope('jeff').findOne();
}).then(jeff => {
expect(jeff.aNumber).to.equal(2);
}).then(() => {
return User.findOne({
where: {
name: 'Not Jeff'
}
});
}).then(notJeff => {
expect(notJeff.aNumber).to.equal(3);
});
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!