最佳实践:Symfony 评论

Best practices : Symfony comments

在我的应用程序中,我必须允许我的用户评论两种实体:食谱和新闻。

我想知道这样做的最佳做法是什么。 我手动管理的带有 ref_id(integer) 和 ref(string) 的 Comment 对象,或者我的实体和 Comment 对象中的 @ManyToMany(targetEntoty="MyInterfaceHere") 之间的公共接口?

感谢您的回答

好吧,如果 Recipes 和 News 扩展了一个摘要 class

use Doctrine\ORM\Mapping\MappedSuperclass;

/**
 * Abstract base class
 *
 * @MappedSuperclass
 */
abstract class EntityWithComments {
   /**
   *
   *@ORM(many-to-bla)
   */
   private $comments;
   public function addComment(){...};
   public function removeComment(){...};
   public function getComments(){...};
   ... 

你的 class 扩展了它,例如食谱:

class Recipe extends EntityWithComments { ...

这样你就可以

$recipe->addComment($comment);
$news->addComment($comment);

直截了当...