Association methods
There are a few options for creating relational mappings with ORMs. Defining the relations through an ORM can help build your database with the proper attributes and columns automatically, manage associated validations (for example, checking to see whether there is strictly only one related record), and perform optimization patterns on queries when fetching or inserting data. Sequelize offers support for four association patterns:
- HasOne – A one-to-one association where the foreign key references the child model. The attribute is defined on the parent model.
- BelongsTo – A one-to-one association where the foreign key references the parent model. The attribute is defined on the child model.
- HasMany – A one-to-many association where the foreign key references the parent model. The attribute is defined on the child model.
- BelongsToMany – A many-to-many association where a separate model (called a junction table) will...