Doctrine - using the same table for multiple (many-to-many) relationships

Say I have three objects: Page, Product, and Media.

Ok, I would like to have this:

Page <-(many-to-many)-> Media Product <-(many-to-many)-> Media 

Using a common approach to solve this issue, this will make the two tables look very similar.

My question is: can I use one table for both relationships using Doctrine?

I only need a way to propose a new column that indicates whether the copy of the medium in a particular row is “Product” or “Page”.

+4
source share
1 answer

Answer No. A relationship table N: N must have a unique table name. But ... you can create such a structure:

 Page <--1:N--> MyGreatJoinTable <--N:1--> Media Product <--1:N--> MyGreatJoinTable <--N:1--> Media 

You do not need to describe the link, because it refers to another table, but if you want, you can do it.

Of course, MyGreatJoinTable will have at least three columns:

 - PageId - ProductId - MediaId 
+2
source

All Articles