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
merged 2 commits into from Feb 21, 2016

Conversation

4 participants
@matthewheck
Contributor

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) {
expect(err.message).to.equal('Oops!');

This comment has been minimized.

@mickhansen

mickhansen Jan 13, 2016

Contributor

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'}})).to.be.rejectedWith('Oops!');

This comment has been minimized.

@matthewheck

matthewheck Jan 15, 2016

Contributor

Thanks for the tip. Clean up done!

@mickhansen

This comment has been minimized.

Contributor

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
Details

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

@janmeier

This comment has been minimized.

Member

janmeier commented Feb 21, 2016

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

@emersonmsantos7

This comment has been minimized.

emersonmsantos7 commented May 5, 2017

BeforeCount is not in the documentation: http://docs.sequelizejs.com/en/v3/api/hooks/

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