New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a beforeCount hook #5209

merged 2 commits into from Feb 21, 2016


4 participants

matthewheck commented Jan 13, 2016

This provides a solution to #4683. This provides a beforeCount hook to the count query, allowing for the user to change the options of count before the database is queried.

I attempted to add an afterCount hook but, because the count is not attached to the model itself, changing it after the database return would require more substantial (probably breaking) changes. Additionally, can't think of a good use case for changing the count after we have queried the database.

Long time user, first time contributor. Hoping to give back more to this great community!

@matthewheck matthewheck force-pushed the matthewheck:add_beforecount_hook branch from 7b0bcdb to 6174a7c Jan 13, 2016

return this.User.find({where: {username: 'adam'}}).catch (function(err) {

This comment has been minimized.


mickhansen Jan 13, 2016


You can clean up assertions a bit by using stuff like:

return expect(this.User.count({where: {username: 'joe'}})).to.eventually.equal(1);
return expect(this.User.count({where: {username: 'joe'}}))'Oops!');

This comment has been minimized.


matthewheck Jan 15, 2016


Thanks for the tip. Clean up done!


This comment has been minimized.


mickhansen commented Jan 15, 2016

LGTM, @janmeier?

janmeier added a commit that referenced this pull request Feb 21, 2016

@janmeier janmeier merged commit 3289353 into sequelize:master Feb 21, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed

janmeier added a commit that referenced this pull request Feb 21, 2016


This comment has been minimized.


janmeier commented Feb 21, 2016

Yep, LGTM as well - thanks a lot @matthewheck , and sorry for leaving you waiting for so long


This comment has been minimized.

emersonmsantos7 commented May 5, 2017

BeforeCount is not in the documentation:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment