Adding Associations to Schemas
Databases are about tables, and the relationships between them. Consider the data model we’ve been working with throughout this book. Artists have many albums, and albums have many tracks as well as many genres. Let’s drill down to one specific relationship first, the one between artists and albums.
These two data types reside in separate tables, but they’re closely related: each of the albums belongs to a particular artist. At the database level, we connect the two tables with a foreign key: in this case, the artist_id column in albums refers to the primary key of the artists table. In Ecto, we use associations to model these relationships. Associations help reflect the connections between database tables in ...
Get Programming Ecto now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.