I have two classes of the PHP model called Question and SolutionMethod. A category can have many elements, and an element can belong to many categories. I created ManyToMany's relation to both classes:
class Question { private $solutions; public function addItems(\Acme\MyBundle\Entity\SolutionMethod $solution) { $this->solutions[] = $solutions; } public function getSolutions() { return $this->solutions; } [...] }
and
class SolutionMethod { private $questions; public function addCategories(\Acme\MyBundle\Entity\Question $question) { $this->questions[] = $question; } public function getQuestions() { return $this->questions; } [...] }
In my form, this association is rendered using multi-select with the required attribute, but I have some kind of question without SolutionMethod, but I cannot save, and the required message appears.
Solved!
The solution is so simple that I feel like an idiot
class QuestionType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder ->add('solutions', null, array('required' => false)) [...] ; } }
source share