I have a many-to-many relationship between two entities A and B.
So when adding a form, in order to add entityA
to entityB
, I am doing the
In EntityA, you have something like this, right?
public function setEntitiesB($data)
{
$this->entitiesB = $data ;
}
Now because you can also receive single value instead of array of values, you need something like this:
public function setEntitiesB($data)
{
if ( is_array($data) ) {
$this->entitiesB = $data ;
} else {
$this->entitiesB->clear() ;
$this->entitiesB->add($data) ;
}
}
i would check the entityA value in the controller and depending on it create different forms.
in controller:
if ($entityA->getType() == 'a') {
$form = new FormB(); // form with multiple true
} else {
$form = new FormA(); // form with multiple false
}