Relationship patterns
In this section, we will go over the details of each type of relation (except Super-Many-To-Many, which is discussed in a later section), and how to use Sequelize to define the associations. After that, we will update the Avalon Airlines project’s models with associations.
We can combine several association patterns to define a relationship pattern. Sequelize supports four relationship patterns:
- One-to-One – We would use the hasOne and belongsTo associations together.
- One-to-Many – The hasMany and belongsTo associations are used for this pattern.
- Many-to-Many – Two belongsToMany associations are used for this pattern.
- Super-Many-to-Many – Two One-to-Many relations where the One models are still considered symbiotic. This relationship will be explained in further detail in the Creating Super Many-to-Many relationships section.
One-to-One
The One-to-One relational pattern involves the hasOne and...