Answer the question
In order to leave comments, you need to log in
Why doesn't manyToMany binding work in symfony 2?
There are two tables, company and rubric, and a company_rubric relationship table, each company can have multiple categories and each category can also have multiple companies. they are linked by id.
Here is what I wrote (I only insert what is relevant to the connections):
RG\JuristBundle\Entity\Company:
type: entity
table: company
manyToMany:
rubrics:
targetEntity: Rubric
inversedBy: companies
joinTable:
name: jurist.company_rubric
RG\JuristBundle\Entity\Rubric:
type: entity
table: rubric
manyToMany:
companies:
targetEntity: Company
mapped_by: rubrics
joinTable:
name: jurist.company_rubric
joinColumns:
rubric_id:
referencedColumnName: id
inverseJoinColumns:
company_id:
referencedColumnName: id
class Rubric{
private $companies;
public function __construct()
{
$this->companies = new ArrayCollection();
}
}
class Company{
private $rubrics;
public function __construct()
{
$this->rubrics = new ArrayCollection();
}
}
Answer the question
In order to leave comments, you need to log in
0. there is a tag for inserting code
1. clear the cache
2. ./app/console doctrine:schema:validate and show the result
manyToMany:
rubrics:
targetEntity: Rubric
mappedBy: companies
targetEntity: Company
inversedBy: rubrics
joinColumns:
name: rubric_id
referencedColumnName: id
inverseJoinColumns:
name: company_id
referencedColumnName: id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question