HOOKs and INCLUDE
See original GitHub issueHi everybody,
I have added some hook on my models but when this models are include in other models, their don’t call the hooks. For example :
return models.company.findAll({
where : { idUser : idUser },
include : [ {
model : models.ticket , as : 'tickets',
include : [{
model : models.access , as : 'access' ,
include : [
{ model : models.event , as :'events' } ,
{ model : models.eventPricing , as : 'priceItems' }
]
}]
}]
}).then(function(transactions){
return transactions;
}).catch(function(error) {
return error;
});
In this example I have a hook “afterFind” on my models “event” and “eventPricing” but it doesn’t call my hook afterFind. I tried to use this hooks: ‘beforeFindAfterExpandIncludeAll’ but its before Find and me I want it afterFindExpandIncludeModels or something like that I would like to call my hooks for each models event and eventPricing. Does anyone has already been faced to this problem ? Should I use an other Hook to do my job ? If I should, which one plz ? And I’m working with Sequelize 2.0 but I didn’t find other hooks available for with Sequelize 3.0 so. Want to know if I forgot something or if you got a quick solution to fix it, otherwise I’ll figured out with several requests but I prefer to do that in just one 😃
Thanks in advance for your help.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:13
- Comments:18 (7 by maintainers)

Top Related StackOverflow Question
I think adding the attribute
hookswith default set onfalseis the best option. For v7, it might make more sense to switch the default around.I suppose we should add this attribute to the Includable object, right? Meaning, the API would look like this:
I needed to run the
afterFindhook on all my included models, hopefully someone can find this helpful: