Many-to-many relationship
A many-to-many relationship is an association in which multiple instances of each participating entity can relate to multiple instances of the other.
The Well-Grounded Python Developer: How the pros use Python and Flask
A many-to-many relationship is a data relationship in which multiple instances of one entity can be associated with multiple instances of another entity.
- How it is used
- Connects orders to products and users to followed posts without treating either pair as one-to-many.
- How deep it goes
- Works from identifier-based CSV associations through database foreign keys to SQLAlchemy models and relationship attributes.
- Examples
- Uses order items with quantities and a blog’s post-follower table.
- What you can do after
- Apply it via SQLAlchemy to model order items or post followers and access their related records.
Java Persistence with Spring Data and Hibernate epub
A many-to-many association is an association in which multiple instances on each side may be related to multiple instances on the other side.
- How it is used
- Maps associations where multiple users, categories, or other entities can relate to multiple entities on the opposite side.
- How deep it goes
- Explains join-table structure, JPA ownership, collection choice, cascading limits, and explicit intermediary entities, but not query optimization.
- Examples
- Uses User–BillingDetails, Category–Item, and User–Address models with SQL schemas, annotated classes, repositories, and tests.
- What you can do after
- Apply it via JPA annotations or Spring Data JDBC intermediary classes to persist and test many-to-many links.
Read how Java Persistence with Spring Data and Hibernate epub explains many-to-many relationship →
Building Web APIs with ASP.NET Core
A many-to-many relationship is a data-model relationship in which multiple instances of each of two entity types can be associated with multiple instances of the other.
- How it is used
- Models associations where multiple board games can have multiple domains, mechanics, or categories.
- How deep it goes
- Defines junction entities and descends into navigation properties, foreign keys, cascading rules, DbSets, and Fluent API configuration.
- Examples
- Uses BoardGame–Domain, BoardGame–Mechanic, and BoardGame–Category associations represented through junction tables.
- What you can do after
- Build it from scratch by defining related entities, a junction entity, and database-context relationship configuration.
Read how Building Web APIs with ASP.NET Core explains many-to-many relationship →
MongoDB 8.0 in Action, Third Edition
A many-to-many relationship allows multiple documents on each side to be associated with multiple documents on the other side.
- How it is used
- Models cross-collection associations when multiple documents on each side must relate to multiple documents on the other.
- How deep it goes
- Explains embedding, references, DBRefs, and join stages, while stopping short of a complete reference-array schema or index design.
- Examples
- Uses airline routes and airports, including flight and airport documents, to identify and represent the relationship.
- What you can do after
- Evaluate whether to embed or reference related MongoDB documents and select an appropriate join or reference mechanism.
Read how MongoDB 8.0 in Action, Third Edition explains many-to-many relationship →
.NET in Action, Second Edition
A many-to-many relationship allows multiple instances of each of two entity types to be associated with multiple instances of the other.
- How it is used
- Models metadata tagging by associating books and tags in an EF Core relational database.
- How deep it goes
- Explains collection properties and the generated join table, including its compound primary key and foreign keys.
- Examples
- Uses Books and Tags, with each Book and Tag exposing a collection of the other.
- What you can do after
- Apply it via Entity Framework Core by defining collections on both entities and letting EF Core create the join table.
Read how .NET in Action, Second Edition explains many-to-many relationship →
Also covered in
What to know first
- userA user is a person or other principal that interacts with a system or is represented by it.
- foreign keyA foreign key is a column or set of columns whose values reference a key in the same or another relational table, linking records and supporting referential integrity.
- design patternA design pattern is a reusable, general solution structure for a recurring software design problem.
- entityAn entity is a distinct, identifiable object, concept, participant, or record represented in a system's model or data.
Related concepts
- join tableimplemented by · A join table is a relational database table whose rows store key-based associations between records in two other tables, commonly representing a many-to-many relationship.
- edgekind of · An edge is a connection between two vertices or nodes in a graph or related structure, representing a relationship and optionally carrying direction, labels, or weights.
- associationkind of · An association is a relationship between model elements, such as classes, whose instances are connected or can interact.
- association resourceimplemented by · An association resource is an API resource that represents a relationship between specific resources and whose associated endpoints are fixed for the resource's lifetime.
- custom methodaddressed by · A custom method is a user-defined operation or capability added to an interface to provide behavior beyond its predefined functionality.
Questions about many-to-many relationship
What is many-to-many relationship?
A many-to-many relationship is an association in which multiple instances of each participating entity can relate to multiple instances of the other.
Which Manning books explain many-to-many relationship?
The Well-Grounded Python Developer: How the pros use Python and Flask, Java Persistence with Spring Data and Hibernate epub, Building Web APIs with ASP.NET Core, MongoDB 8.0 in Action, Third Edition and .NET in Action, Second Edition.
What should I know before learning many-to-many relationship?
Manning books that teach many-to-many relationship usually introduce user, foreign key, design pattern and entity first.
What is the difference between many-to-many relationship and intermediate entity?
A many-to-many relationship is an association in which multiple instances of each participating entity can relate to multiple instances of the other. An intermediate entity is a persistent entity that represents the association between two other entities and can carry association-specific state.
What is many-to-many relationship a kind of?
Many-to-many relationship is a kind of edge. An edge is a connection between two vertices or nodes in a graph or related structure, representing a relationship and optionally carrying direction, labels, or weights.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




