Many-to-Many Associations
Explore how to implement many-to-many associations in Ecto by using join tables and schemas. Understand how to link records such as albums and genres efficiently without extra schemas, and learn when to create schemas for join tables with additional fields.
We'll cover the following...
We’re now going to look at a more complex association—many-to-many. These relationships are not as straightforward as belongs_to relationships because we need an extra table to implement them.
Example of a many-to-many relationship
An excellent example of a many-to-many relationship is assigning genres to albums. Genres describe the musical style of an album, such as jazz, classical, rock, blues and so on. We want to be able to assign more than one genre for each album. We also want to associate each genre with more than one album. For example, we’ll have one record in the genres table for ...