title: Symfony ManyToMany Form
body: <p>I have entity skill and language, speciality, platforms entity with relation ManyToMany and when I create skill I select language, speciality, platforms and form is valid and normal persist and flush in DB. But when I create language or speciality or platforms  I have error This value is not valid and in debug panel in form. Why I'm not understand, help please:</p>
  
  <pre><code>Message Origin  Cause
  This value is not valid.    skills  Symfony\Component\Validator\ConstraintViolation
  Object(Symfony\Component\Form\Form).children[skills] = [0 =&gt; AngularJS, 1 =&gt; API]
  
  Caused by:
  
  Symfony\Component\Form\Exception\TransformationFailedException
  Unable to reverse value for property path "skills": Could not find all matching choices for the given values
  
  Caused by:
  
  Symfony\Component\Form\Exception\TransformationFailedException
  Could not find all matching choices for the given values
  </code></pre>
  
  <p>In entities I delete </p>
  
  <pre><code>/**
   * Constructor
   */
  public function __construct()
  {
      $this-&gt;language = new \Doctrine\Common\Collections\ArrayCollection();
      $this-&gt;platforms = new \Doctrine\Common\Collections\ArrayCollection();
      $this-&gt;specialities = new \Doctrine\Common\Collections\ArrayCollection();
  }
  </code></pre>
  
  <p>and in language, speciality, platforms deleted too</p>
  
  <p>entities:</p>
  
  <pre><code>class Skill
  {
  use Timestampable;
  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @var \MyBundle\Entity\CodeDirectoryProgramLanguages
   *
   * @ORM\ManyToMany(targetEntity="CodeDirectoryProgramLanguages", inversedBy="skills", cascade={"persist"})
   */
  protected $language;
  
  /**
   * @var \MyBundle\Entity\CodeDirectoryPlatforms
   *
   * @ORM\ManyToMany(targetEntity="CodeDirectoryPlatforms", inversedBy="skills", cascade={"persist"})
   */
  protected $platforms;
  
  /**
   * @var \MyBundle\Entity\CodeDirectorySpecialities
   *
   * @ORM\ManyToMany(targetEntity="CodeDirectorySpecialities", inversedBy="skills", cascade={"persist"})
   */
  protected $specialities;
  </code></pre>
  
  <p>and an example:</p>
  
  <pre><code>class CodeDirectorySpecialities
  {
  use Timestampable;
  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @var string
   *
   * @ORM\Column(name="specialities", type="string", length=255)
   */
  private $specialities;
  
  /**
   * @ORM\ManyToMany(targetEntity="MyBundle\Entity\Skill", mappedBy="specialities", cascade={"persist"})
   */
  protected $skills;
  </code></pre>
  
  <p>and add to all entity </p>
  
  <pre><code>    public function __toString()
  {
      return $this-&gt;string_filed_entity;
  }
  </code></pre>
  
  <p>this my form</p>
  
  <pre><code>    public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('specialities');
  
              $builder-&gt;add('skills','entity',
                  array(
                      'class'=&gt;'MyBundle\Entity\Skill',
                      'property'=&gt;'skill',
                      'multiple'=&gt;true,
                      'expanded' =&gt; true,
                  )
              );
  }
  </code></pre>
  
  <p>and action</p>
  
  <pre><code>        $entity = new CodeDirectorySpecialities();
      $form = $this-&gt;createCreateForm($entity);
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isValid()) {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
              $skills = $entity-&gt;getSkills()-&gt;getValues();
          if(!empty($skills)){
              foreach($skills as $skill){
                  $skill-&gt;addSpeciality($entity);
                  $em-&gt;persist($skill);
              }
          }
  
          $em-&gt;persist($entity);
          $em-&gt;flush();
  
          return $this-&gt;redirect($this-&gt;generateUrl('specialities_show', array('id' =&gt; $entity-&gt;getId())));
      }
  </code></pre>