Querying associations with eager loading and lazy loading
Sequelize offers two different methods of querying associations depending on how you wish to query the data: eager loading and lazy loading. With eager loading, you would load all of the associated data at once. The lazy loading method will load the associations per query as they are called upon from the code. It is easier to explain eager loading than lazy loading but to see the benefits of eager loading, we will need to go over lazy loading first.
Note
You may have heard of the “N+1 select problem” with other ORM frameworks; this is referring to the lazy loading method (although, not mutually exclusive) and how selecting an association per row could be hazardous to your application’s performance.
Lazy loading
Sequelize tries to make no presumptions about your intent and will initially select only the model’s data. We will need to explicitly call the associations if we want to transverse...