BeforeFind hook called without model
See original GitHub issueHi, 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:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sushantdhiman It is not clear though that a function you had through
addHook()
will be attached/applied withthis
to the Model @euqen If you want to do a PR I think this would be a nice addition to the docsNo need to add this in docs, calling a method on object will point to that object via
this