N
N
Nikolai Egorov2018-10-03 14:26:23
symfony
Nikolai Egorov, 2018-10-03 14:26:23

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;
}

But what about the essence of the review - is it necessary to add the properties of all 3 types of links to it? Or not add any properties at all?
class Review
        /**
         * @ORM\ManyToOne(targetEntity="Reviews")
         */
        private $article;

        /**
         * @ORM\ManyToOne(targetEntity="Reviews")
         */
        private $post;

        /**
         * @ORM\ManyToOne(targetEntity="Reviews")
         */
        private $image;
}

Something seems to me that I wrote nonsense ...
Is it possible in this situation to get by with one Review review entity? Or do you need to make your own review object for each entity, such as: ArticleReview for articles, ImageReview for picture reviews, and PostReview for post reviews?
Please don't kick too hard - I'm just learning))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
padlyuck, 2018-10-03
@nickicool

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

I
Ivan Shumov, 2018-10-03
@inoise

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 question

Ask a Question

731 491 924 answers to any question