skip to Main Content
+971 55 881 1725 hmimthiaz @ imthi.com

Symfony Doctrine Many to Many Relationship (ManyToMany)

Many to many relations are one of the mostly used relations in the relational database. It took a while for me to figure how to properly configure this relation in Symfony Doctrine. I am sharing this so it might be useful for someone.

Used very simple example students and course. A student can opt for multiple courses and a single course can be opted by multiple students.

And Entity class should be like this…

The above entities will create the following SQL and it will also create the cross-reference table.

Hope this helps 😉

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top