title: Update many-to-many association doctrine2
body: <p>Is there any solution to do this automatically? </p>
  
  <p>My two entities:</p>
  
  <pre><code>class User
  {
      /* *
      * @ManyToMany(targetEntity="Product", inversedBy="users")
      * @JoinTable(name="user_product",
      *  joinColumns={@JoinColumn(name="user_id", referencedColumnName="idUser")},
      * inverseJoinColumns={@JoinColumn(name="product_id", referencedColumnName="idProduct")}
      * 
      * )
      */
  protected $products;
  }
  
  class Product {
      /**
      * @ManyToMany(targetEntity="User", mappedBy="products")
      */
  protected $users;
  }
  </code></pre>
  
  <p><strong>User</strong> entity exists with two <strong>Products</strong> already associated ids (<code>1</code>, <code>2</code>):</p>
  
  <pre><code>$user = $entityManager-&gt;find('User', 1);
  </code></pre>
  
  <p>This array came from view with new <strong>Products</strong> data to be inserted, deleted or if already in list do nothing:</p>
  
  <pre><code>$array = array(1, 3, 4);
  </code></pre>
  
  <p>In this case:</p>
  
  <pre><code>1 = Already in association with User (do nothing)
  2 = not in array and should be deleted
  3 = should be inserted
  4 = should be inserted
  </code></pre>
  
  <p>How to do this in doctrine2? Is there a merge function that do it automatically or shoud I do it manually?</p>