title: Symfony2 - Error with a form that create an association (Many to Many)
body: <p>I have 2 entities in a Many-To-Many association.</p>
  
  <pre><code>/**
   * @ORM\Table()
   * @ORM\Entity()
   */
  class Clown
  {
      ...
      /**
       * @ORM\ManyToMany(targetEntity="Appuntamento", inversedBy="partecipanti")
       * @ORM\JoinTable(name="partecipa")
       */
      private $appuntamenti;
  
      public function __construct() {
          $this-&gt;appuntamenti = new ArrayCollection();
      }
      ...
      public function addAppuntamenti(Appuntamento $app)
      {
          $this-&gt;appuntamenti[] = $app;
      }    
  
      public function getAppuntamenti()
      {
          return $this-&gt;appuntamenti;
      }
  }
  
  /**
   * @ORM\Table()
   * @ORM\Entity()
   */
  class Appuntamento
  {
      /**
       * @ORM\ManyToMany(targetEntity="Clown", mappedBy="appuntamenti")
       */
      private $partecipanti;
  
      public function __construct() {
          $this-&gt;partecipanti = new ArrayCollection();
      }
      ...
      public function addPartecipanti(Clown $partecipante)
      {
          $partecipante-&gt;addAppuntamenti($this);
          $this-&gt;partecipanti[] = $partecipante;
      }    
  
      public function getPartecipanti()
      {
          return $this-&gt;partecipanti;
      }
  }
  </code></pre>
  
  <p>Then I create a form that allow to set the attendee (aka "partecipanti") of an Appuntamento.</p>
  
  <pre><code>namespace Clown\DiaryBundle\Form;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilder;
  
  class PartecipantiType extends AbstractType
  {
      public function buildForm(FormBuilder $builder, array $options)
      {
          $builder
              -&gt;add('title')  
              -&gt;add('partecipanti', 'entity', array(
                      'class' =&gt; 'ClownDiaryBundle:Clown',
                      'property' =&gt; 'drname',
                      'multiple'  =&gt; true,
                      'expanded'  =&gt; true,
              ))
          ;
      }
  
      public function getName()
      {
          return 'clown_diarybundle_partecipantitype';
      }
  }
  </code></pre>
  
  <p>In the controller now I create the actions, one that shows the form, and one that update the entity.</p>
  
  <pre><code>/**
   * @Route("/{id}/partecipanti", name="admin_appuntamento_partecipanti")
   * @Template()
   */
  public function partecipantiAction($id)
  {
      $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
      $entity = $em-&gt;getRepository('ClownDiaryBundle:Appuntamento')-&gt;find($id);
  
      if (!$entity) {
          throw $this-&gt;createNotFoundException('Unable to find Appuntamento entity.');
      }
  
      $partecipantiForm = $this-&gt;createForm(new PartecipantiType(), $entity);
  
      return array(
          'entity'      =&gt; $entity,
          'partecipanti_form'   =&gt; $partecipantiForm-&gt;createView(),
      );
  }
  
  /**
   * @Route("/{id}/update_partecipanti", name="admin_appuntamento_update_partecipanti")
   * @Method("post")
   * @Template("ClownDiaryBundle:Appuntamento:partecipanti.html.twig")
   */
  public function updatePartecipantiAction($id)
  {
      $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
      $entity = $em-&gt;getRepository('ClownDiaryBundle:Appuntamento')-&gt;find($id);
  
      if (!$entity) {
          throw $this-&gt;createNotFoundException('Unable to find Appuntamento entity.');
      }
  
      $partecipantiForm = $this-&gt;createForm(new PartecipantiType(), $entity);
      $request = $this-&gt;getRequest();
      $partecipantiForm-&gt;bindRequest($request);
  
      if ($partecipantiForm-&gt;isValid()) {
          $em-&gt;persist($entity);
          $em-&gt;flush();
  
          return $this-&gt;redirect($this-&gt;generateUrl('admin_appuntamento_show', array('id' =&gt; $id)));
      }
  
      return array(
          'entity'      =&gt; $entity,
          'partecipanti_form'   =&gt; $partecipantiForm-&gt;createView(),
      );
  }
  </code></pre>
  
  <p>But when I get the post in the second action, and I try to persist the object, no association (between Clown and Appuntamento) has been created.
  Am I forgotting something?</p>