I am implementing a system with two entities: Product and Category. I want to create a many-to-many relations between these two entities but I don't want to use the many-to-many option in Doctrine. I want to be able to create the middle table (product-category) by myself so that later I can access this table as well. How should I define the relationships between these three tables? (Considering that the relationship between product and category is many-to-many in my project). Simple demonstrative examples with doctrine ORM annotations is much appreciated so I don't get this wrong. Many thanks. What is the best practice?
Asked
Active
Viewed 515 times
2
-
look at this question http://stackoverflow.com/questions/15616157/doctrine-2-and-many-to-many-link-table-with-an-extra-field – Denis Alimov Jun 10 '16 at 05:54
-
That will be simple combination o one-to-many any many-to-one relations. – Jakub Matczak Jun 10 '16 at 08:21
1 Answers
4
You can add a middle entity called, for example, "ProductCategory". Then you create a one-to-many relationship between "Product" and "ProductCategory" and another one-to-many relationship between "Category" and "ProductCategory".
This solution even allows you to add some extra fields to "ProductCategory" table.
Product [1]------>[n] ProductCategory [n]<-------[1] Category

Max Leske
- 5,007
- 6
- 42
- 54

Thomas Shelby
- 1,340
- 3
- 20
- 39