title: Symfony2 form collection: How to remove entity from a collection?
body: <p>I try to remove entities from a collection but it doesn't work. </p>
  
  <p>I think I have a mistake somewhere, but I don't know where.</p>
  
  <p>Here the code from my <code>updateAction</code>: </p>
  
  <pre><code>    $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
      $entity = new Person();
  
      if (!$entity) {
          throw $this-&gt;createNotFoundException('Unable to find Person entity.');
      }
  
      $editForm   = $this-&gt;createForm(new PersonType(), $entity);
      $deleteForm = $this-&gt;createDeleteForm($id);
  
      $request = $this-&gt;getRequest();
  
      $editForm-&gt;bindRequest($request);
  
      if ($editForm-&gt;isValid()) {
          $entity = $editForm-&gt;getData();
  
          $em-&gt;persist($entity);
          foreach($entity-&gt;getAddresses() as $address)
          {               
              $em-&gt;persist($address);
          }
          $em-&gt;flush();                                 
  
          return $this-&gt;redirect($this-&gt;generateUrl('person_show', array('id' =&gt; $id)));
      }
  
      return $this-&gt;render('AppPersonBundle:Person:edit.html.twig', array(
          'entity'      =&gt; $entity,
          'edit_form'   =&gt; $editForm-&gt;createView(),
          'delete_form' =&gt; $deleteForm-&gt;createView(),
  
      );
  </code></pre>
  
  <p>Note that to remove my entity I remove the div from the html. </p>
  
  <p>I mean I remove <code>&lt;div id="myapp_personbundle_persontype_address_4"&gt;</code> for example.</p>
  
  <p>Is it the right way?</p>