O'Reilly logo

Persistence in PHP with Doctrine ORM by Kévin Dunglas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding the @ManyToMany annotation with tags

Tags group posts by topics. A tag contains several posts, and a post has several tags. This is a Many-To-Many bidirectional association. Doctrine manages transparently the association table needed to store Many-To-Many relations at the SQL level. The MySQL schema that will be generated is shown in the following screenshot:

Understanding the @ManyToMany annotation with tags

Creating the Tag entity class (inverse side)

The Tag entity class has only two properties:

  • name: This is the name of the tag, it is unique, and is the identifier of the entity
  • posts: This is the collection of posts associated with this tag

The following are the steps to create the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required