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 called without model

See original GitHub issue

Hi, everyone! Doing:

let MyModel = db.define('MyModel', {...}, {...})
MyModel.findOne({ where: {id: 'my-id'}})
MyModel.addHook('beforeFindAfterOptions', function(options) {
    console.log(options.model); // undefined
};

MyModel.addHook('beforeFind', function(options) {
    console.log(options.model); // undefined
};

After query above, this hooks have been called without model MyModel included. I think it might be better to always include current model to hook arguments, because currently I need to determine by what model I performing query.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
felixfbeckercommented, Nov 7, 2016

@sushantdhiman It is not clear though that a function you had through addHook() will be attached/applied with this to the Model @euqen If you want to do a PR I think this would be a nice addition to the docs

0reactions
sushantdhimancommented, Nov 7, 2016

No need to add this in docs, calling a method on object will point to that object via this

Read more comments on GitHub >

github_iconTop Results From Across the Web

beforeFind hook not called when model is included #4546
In my beforeFind hook I add a few includes that I want to always load with this model, so I'm trying to have...
Read more >
Hooks - Sequelize
Hooks (also known as lifecycle events), are functions which are called before and ... This hook is always run, whether or not the...
Read more >
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 >
Hooks | Objection.js
There's no $beforeFind hook, because we don't have any model instances before the query is executed. There's nothing to call the hook for....
Read more >
Mongoose v6.8.1: Middleware
Middleware (also called pre and post hooks) are functions which are passed ... Calling pre() or post() after compiling a model does not...
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