title: Updating (from the inverse side) bidirectional many-to-many relationships in Doctrine 2?
body: <p><code>Customer</code> is the inverse side of "keywords/customers" relationship with <code>Keyword</code>:</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>/**
   * @ORM\ManyToMany(targetEntity="Keyword", mappedBy="customers",
   *     cascade={"persist", "remove"}
   * )
   */
  protected $keywords;
  </code></pre>
  
  <p>When creating a new customer, one should select one or more keywords. The entity form field is:</p>
  
  <pre class="lang-php prettyprint-override"><code>$form-&gt;add($this-&gt;factory-&gt;createNamed('entity', 'keywords', null, array(
      'class'    =&gt; 'Acme\HelloBundle\Entity\Keyword',
      'property' =&gt; 'select_label',
      'multiple' =&gt; true,
      'expanded' =&gt; true,
  )));
  </code></pre>
  
  <p>In my controller code, after binding the request and check if form is valid, I need to persist both the customer and all customer/keyword(s) associations, that is the join table.</p>
  
  <p>However customer is the inverse side, so this is not working:</p>
  
  <pre class="lang-php prettyprint-override"><code>if($request-&gt;isPost()) {
      $form-&gt;bindRequest($request);
  
      if(!$form-&gt;isValid()) {
          return array('form' =&gt; $form-&gt;createView());
      }
  
      // Valid form here   
      $em = $this-&gt;getEntityManager();
  
      $em-&gt;persist($customer);    
      $em-&gt;flush();
  }
  </code></pre>
  
  <p>Event with "cascade" option, this code fails. <code>$customer-&gt;getKeywords()</code> will return <code>Doctrine\ORM\PersistentCollection</code>, which holds only selected keywords.</p>
  
  <p>Should I manually check which keyword was removed/added and then update from the owning side?</p>