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 @ManyToOne and @OneToMany annotations with the comment system

Let's start with the comments. Visitors to our blog should be able to react to our posts. We have to create a new Comment Doctrine entity type storing the reader's comments. Comment entities will be linked to one Post entity. One post can have many comments, and one comment is associated with a sole post.

The following E-R diagram represents the MySQL schema that will be generated using mapping information:

Understanding the @ManyToOne and @OneToMany annotations with the comment system

Creating the Comment entity class (owning side)

The Comment entity has the following four properties:

  • id: This is a unique identifier of the comment
  • body: This represents ...

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