sequelize / sequelize/sequelize

HOOKs and INCLUDE

Open
#4,627 21 comments 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
30.4k
Forks
4.3k
Avg merge
1d 6h
Merged PRs (30d)
68

Description

Hi 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the nested include query with Sequelize 2.0 and the afterFind hooks on event and eventPricing shown in the issue. Trace how hooks are handled for included models, then verify whether the expected behavior is supported or missing. Done means the issue has a confirmed behavior and, if applicable, a regression test showing hooks run for the nested included models.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.