Arraycollection:映射关联彼此不一致

时间:2014-01-26 18:14:27

标签: php symfony doctrine-orm arraycollection

我有一个与之关联的用户实体和任务实体

在symfony的分析器中,我得到两个错误。

对于Acme \ ManagementBundle \ Entity \ User类,我得到:

The mappings Acme\ManagementBundle\Entity\User#missions and Acme\ManagementBundle\Entity\Mission#users are incosistent with each other.

对于Acme \ ManagementBundle \ Entity \ Mission类,我得到:

The association Acme\ManagementBundle\Entity\Mission#users refers to the inverse side field Acme\ManagementBundle\Entity\User#users which does not exist.

我试着自己解读here,但我不能。

我的任务实体是:

班级使命{

    /**
     * @ORM\ManyToMany(targetEntity="Acme\ManagementBundle\Entity\User", inversedBy="users")
     */
    protected $users;

    public function __construct(){
        $this -> users = new ArrayCollection();
    }

        /**
     * Add users
     *
     * @param \Acme\ManagementBundle\Entity\User $users
     * @return Mission
     */
    public function addUser(\Acme\ManagementBundle\Entity\User $users)
    {
        $this->users[] = $users;

        return $this;
    }

    /**
     * Remove users
     *
     * @param \Acme\ManagementBundle\Entity\User $users
     */
    public function removeUser(\Acme\ManagementBundle\Entity\User $users)
    {
        $this->users->removeElement($users);
    }

    /**
     * Get users
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getUsers()
    {
        return $this->users;
    }
//...
}

我的用户实体:

abstract class User extends BaseUser
{

     /**
     * @ORM\ManyToMany(targetEntity="Acme\ManagementBundle\Entity\Mission", mappedBy="users")
     */
    protected $missions;    
    public function __construct(){
        parent::__construct();
        $this -> missions = new ArrayCollection();
    }
    /**
     * Add missions
     *
     * @param \Acme\ManagementBundle\Entity\Mission $missions
     * @return User
     */
    public function addMission(\Acme\ManagementBundle\Entity\Mission $missions)
    {
        $this->missions[] = $missions;

        return $this;
    }

    /**
     * Remove missions
     *
     * @param \Acme\ManagementBundle\Entity\Mission $missions
     */
    public function removeMission(\Acme\ManagementBundle\Entity\Mission $missions)
    {
        $this->missions->removeElement($missions);
    }

    /**
     * Get missions
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getMission()
    {
        return $this->missions;
    }
}

1 个答案:

答案 0 :(得分:3)

users类的Mission属性中有错误的注释。它应该是:

/**
 * @ORM\ManyToMany(targetEntity="Acme\ManagementBundle\Entity\User", inversedBy="missions")
 */
protected $users;