Php symfony 2中嵌套的可连接列,带有原则2

Php symfony 2中嵌套的可连接列,带有原则2,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,因此,给定实体注释,让CommentPerson找出CommentPersonisModerator(),最干净的方法是什么 使用存储库不会弄脏手指 /** * @ORM\Entity(repositoryClass="MyApp\MyBundle\Repository\CommentRepository") * @ORM\Table(name="comment") */ class Comment { /** * @ORM\Id * @ORM\Column(t

因此,给定实体注释,让CommentPerson找出CommentPerson
isModerator()
,最干净的方法是什么

使用存储库不会弄脏手指

/**
 * @ORM\Entity(repositoryClass="MyApp\MyBundle\Repository\CommentRepository")
 * @ORM\Table(name="comment")
 */
class Comment
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="integer")
     */
    protected $user_id; //id of entity User

      /**
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     **/
    protected $user; //a user can have many comments


    /**
     * @ORM\Column(type="text")
     */
    protected $commentText;

}


/**
 * @ORM\Entity(repositoryClass="MyApp\MyBundle\Repository\UserRepository")
 * @ORM\Table(name="user")
 */
class User //this is the web user
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="integer")
     */
    protected $person_id; //id of entity Person

      /**
     * @ORM\ManyToOne(targetEntity="Person")
     * @ORM\JoinColumn(name="person_id", referencedColumnName="id")
     **/
    protected $person; //many web users can map to one actual person


    public function getPerson()
    {
        return $this->person;
    }
}

/**
 * @ORM\Entity(repositoryClass="MyApp\MyBundle\Repository\PersonRepository")
 * @ORM\Table(name="person")
 */
class Person
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="text")
     */
    protected $email;

    /**
     * @ORM\OneToMany(targetEntity="CommentPerson", mappedBy="person")
     * @ORM\JoinColumn(name="id", referencedColumnName="person_id")
     */
    private $commentPersons; //one person can have many commentPersons (since one person can be part in many different comment sections, not shown in code here, but take it as a fact)

}


/**
 * @ORM\Entity(repositoryClass="MyApp\MyBundle\Repository\CommentPersonRepository")
 * @ORM\Table(name="comment_Person")
 */
class CommentPerson
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="integer")
     */
    protected $person_id; //this is the id of the entity Person

    /**
     * @ORM\Column(type="boolean")
     */
    protected $isModerator;

}

评论是由评论人创建的吗?如果是这样,则注释实体似乎应该链接到CommentPerson,而不是(或另外)UserModerator应该是一个角色,例如Admin或Super Admin。那么您想如何做到这一点,您需要在几个实体中保存角色。这以后可能会制造麻烦。在FOSUserBundle看你。这可能是一个好的开始。对于控件,无论是否只有版主想要访问评论,都要编写一个投票者()。