Skip to content

Instantly share code, notes, and snippets.

View styts's full-sized avatar

Kirill Stytsenko styts

View GitHub Profile
@elliette
elliette / ManyToManyRelationships.md
Last active October 31, 2023 16:03
Describing `belongsToMany` and `hasMany` methods in Sequelize

Defining Many-to-Many Associations in Sequelize

Reference: Sequelize docs on association

Let’s say we have two models: Films and Festivals

We know that a film can be shown at many film festivals and that, conversely, a festival can show many films. This is what is known as a many-to-many relationship.

Knowing this, we can set up our associations: