Answer the question
In order to leave comments, you need to log in
How to implement reviews for multiple entities?
I'm learning Symfony, and I don't quite understand how you can implement a review entity so that there is one table for reviews, but they can be assigned to different entities, such as Article, Image, Post. I reason like this:
- Each of the Article, Image, Post entities can have many reviews.
- but each of the reviews can only have one of these entities.
For example, one Article object can have many instances of the Review object - this is OneToMany, if I understand correctly. So the Article class turns out like this (I'm mainly concerned about the correctness of the properties of objects and their annotations, because I can confuse due to inexperience):
// аналогичный класс и для сущностей Image и Post
class Article
/**
* @ORM\OneToMany(targetEntity="Review")
* @ORM\JoinColumn(referencedColumnName="id", nullable=true)
*/
private $reviews;
}
class Review
/**
* @ORM\ManyToOne(targetEntity="Reviews")
*/
private $article;
/**
* @ORM\ManyToOne(targetEntity="Reviews")
*/
private $post;
/**
* @ORM\ManyToOne(targetEntity="Reviews")
*/
private $image;
}
Answer the question
In order to leave comments, you need to log in
https://www.doctrine-project.org/projects/doctrine... or https://www.doctrine-project.org/projects/doctrine... to organize all comments in one table. Judging by the documentation, you will have to make a parent comment class and 3 classes of concrete comment entities regarding what they are attached to. Yes, and different functionality will be easier to distribute later, and not interfere with a bunch of horses with people
This is a one-way link through intermediate link tables. You can do it differently, but not really. You don't need feedback. Not for development.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question