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 šŸ˜‰

ORM Designer 2 – Why do you need it?

For sometime now I have been busy working with Symfony 2. The more I work with this framework the more I am falling in love with it. There are so many features for which I love Symfony. One such is tight integration with Doctrine ORM.

Symfony comes with set of command line tools which helps you with your ORM entites creation. But it was not visual and is a one shot creation tool and if you need to update or make any changes it was not possible, you need to edit these files definations manually. I was in hunt for a good tool which will make my life easier for managing my entities and its relations. So I was Googling and I found this great tool ORM Designer.

logo_header

This tool has an amazing intergration with Symfony. You can import the existing entities into the designer and make any changes to the one and export the same back to the project. It supports YAML, XML and best part of all Annotation.

Why do you need it?

  • To be honest it saves a lot of time editingĀ your entities and easily exporting it
  • You get clear view of what you are dealing with and how your relationships are mapped
  • You don’t have to remember all the annotation and it’sĀ constraints
  • Avoid relationships mistakes which I do all the time
  • Error free definitions

Pros

  • Easy import of existing Symfony projects
  • Visualisation of Entities and their relationships
  • Organising Entities by Bundles
  • Easy export of modifications back to your Symfony2 project

Cons

  • Editors needs more shortcuts and easy to copy paste fields across entities
  • Drag and Drop Features
  • Should remember the imported source file, and facility to update modification from theĀ source file
  • They should be seriously thinking of a different pricing model. USD 400 is lot of money !! Make itĀ cheaper so that It can reach more developers.

Why do you start usingĀ ORM Designer today as they offer 14 days fully functional trial version. Share your feedback how it goes šŸ˜‰

Back To Top