I have two objects: User and Company, as well as the relationship between them: n: m. In my organization User.php, I have this code:
protected $companies;
public function __construct() {
$this->companies = new \Doctrine\Common\Collections\ArrayCollection();
}
public function setCompanies(\PL\CompanyBundle\Entity\Company $companies) {
$this->companies = $companies;
}
public function getCompanies() {
return $this->companies;
}
And in my object Company.php, I have this other code:
protected $users;
public function __construct() {
$this->users = new \Doctrine\Common\Collections\ArrayCollection();
}
But I got this error:
ContextErrorException: Note: Undefined index: inverseJoinColumns in / var / www / html / apps / portal _de_logistica / vendor / doctrine / orm / lib / Doctrine / ORM / Persisters / BasicEntityPersister.php line 1041
What is wrong with mapping?
EDIT Refractor Code
Following the instructions from @ ahmed-siouani, I made the following changes:
User.php
/**
* @ORM\ManyToMany(targetEntity="PL\CompanyBundle\Entity\Company", inversedBy="users")
* @ORM\JoinTable(name="fos_user_user_has_company",
* JoinColumns={@ORM\JoinColumn(name="fos_user_user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="company_id", referencedColumnName="id")}
* )
*/
protected $companies;
where fos_user_user_has_companyis the table added for the relationship n:m.
Company.php
protected $users;
And now the error:
AnnotationException: [ ] @ORM\JoinTable \Sonata\UserBundle\Entity\User:: $ "JoinColumns". : , , joinColumns, inverseJoinColumns
?