question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

beforeFind hook not called when model is included

See original GitHub issue

When doing

Model.findOne({ include: [ ModelWithBeforeFindHook ] }).then(result => {
  ...
});

The beforeFind hook is not called, and there is no other hook to use in this scenario.

In my beforeFind hook I add a few includes that I want to always load with this model, so I’m trying to have this happen also when the model is included.

I’m expecting beforeFind to be called, if this is not desired then I think a new hook should be added to solve this.

Discuss 😃

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
diosneycommented, Sep 30, 2016

Ohh, just forgot, in my use case I needed to trigger the afterFind hook in the included model.

0reactions
diosneycommented, Sep 30, 2016

Right now what I’m doing is defining two hasMany associations in a common model manually defined by me (ex: ABMemberships) instead of the belongsToMany. That, with separate in mind for the hasMany did the trick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sequelize afterFind hook not executed when querying with ...
My question is: Why are the hooks not being executed when the model -- on which the hooks are specified -- is included...
Read more >
afterFind Hook not called with correct values or not ...
I have a smart field role on the user model. This field is populated with a query to userRole. To improve performance I...
Read more >
Hooks
Hooks (also known as lifecycle events), are functions which are called before and after calls in sequelize are executed. For example, if you...
Read more >
beforeGet - Velo API Reference
A hook that is triggered before a get() operation. The beforeGet() hook runs when the get() function is called. The hook does not...
Read more >
Instance Methods | Objection.js
Creates a query builder for this model instance. ... For deletes there is no instance for which to call the hook, except when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found