Skip to content

add a beforeCount hook#5209

Merged
janmeier merged 2 commits intosequelize:masterfrom
matthewheck:add_beforecount_hook
Feb 21, 2016
Merged

add a beforeCount hook#5209
janmeier merged 2 commits intosequelize:masterfrom
matthewheck:add_beforecount_hook

Conversation

@matthewheck
Copy link
Copy Markdown
Contributor

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!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip. Clean up done!

@mickhansen
Copy link
Copy Markdown
Contributor

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
janmeier added a commit that referenced this pull request Feb 21, 2016
@janmeier
Copy link
Copy Markdown
Member

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

@emersonmsantos7
Copy link
Copy Markdown

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

@josephgrossberg
Copy link
Copy Markdown

Update: still no mention in the docs http://docs.sequelizejs.com/

This is a cool feature that merits documenting. How can I help? ping @sdepold

@aat2703
Copy link
Copy Markdown

aat2703 commented Sep 5, 2019

Why not just firing beforeFind hook? It seems odd

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants