I have an User entity and a mission entity, that are associated
In the profiler of symfony i get two errors.
For the class Acme\ManagementBundle\Entity\User I get:
The mappings Acme\ManagementBundle\Entity\User#missions and Acme\ManagementBundle\Entity\Mission#users are incosistent with each other.
For the class Acme\ManagementBundle\Entity\Mission I get:
The association Acme\ManagementBundle\Entity\Mission#users refers to the inverse side field Acme\ManagementBundle\Entity\User#users which does not exist.
I tried to solve by myself reading here but I could't.
My mission entity is:
class Mission {
/**
* @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;
}
//...
}
And my user entity:
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;
}
}
You have wrong annotation in the users
property in Mission
class. It should be:
/**
* @ORM\ManyToMany(targetEntity="Acme\ManagementBundle\Entity\User", inversedBy="missions")
*/
protected $users;