title: Symfony2 remove and save many to many relations
body: <p>I need your help today. I'm working on a small application using Symfony 2.1 but I have a base problem, I have to tables with a many to many relation which creates a third table:</p>
  
  <pre><code>class Usuario implements UserInterface {
  /**
  * @ORM\ManyToMany(targetEntity="Alood\BackBundle\Entity\Alergeno", inversedBy="usuarios")
  * @ORM\JoinTable(name="UsuariosProductos",
   *      joinColumns={@ORM\JoinColumn(name="usuario_user", referencedColumnName="user")},
   *      inverseJoinColumns={@ORM\JoinColumn(name="alergeno_id", referencedColumnName="id")}
   *      )
  **/
  protected $alergenos;
  }
  
  
  public function __construct(){
      $this-&gt;alergenos = new ArrayCollection();
  }
  
  public function getAlergenos() { return $this-&gt;alergenos; }
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>/**
  * @ORM\ManyToMany(targetEntity="Alood\BackBundle\Entity\Usuario", mappedBy="alergenos")
  **/
  protected $usuarios;
  </code></pre>
  
  <p>Then I need to remove the non selected Alergenos, this is my controller:</p>
  
  <pre><code>$alergenosUser = $em-&gt;getRepository("BackBundle:Usuario")-&gt;find($usuario);
  
  $resultSym = array_diff($alergenosUsuarioIds, $alergen);
  
  foreach($resultSym as $result) {
      $alergenosUser-&gt;getAlergenos()-&gt;remove($result);
  }
  $em-&gt;persist($alergenosUser);
  $em-&gt;flush();
  </code></pre>
  
  <p>Could you please help me to figure out what I'm doing wrong? Thanks you so much!</p>