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:
Creating the Comment entity class (owning side)
The Comment
entity has the following four properties:
id
: This is a unique identifier of the commentbody
: This represents ...
Get Persistence in PHP with Doctrine ORM now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.