In this post, we will be sharing with you a tip on how to define many to many relationships in dbdiagram.
Many to Many Relationship
A lot of people ask for this feature, however, many-to-many is not a kind of relationship that we can present it on your diagrams directly. We need to create an associative (join) table instead of drawing the relationship directly.
We have 2 tables: Authors and Books. An Author can write several Books, and a Book can be written by several Authors
Many Books are related to many Authors, however, it’s not possible to draw a single relationship line here since both tables don’t have anything to connect. In this case, to present this relationship, you need to create an associative table author_book to connect them.
An Order can have multiple Products, a Product can be ordered in multiple Orders
Students and Classes
A Student can enroll multiple Classes and a Class can be enrolled by multiple Students