title: Define unique columns on ManyToMany in Doctrine
body: <p>I'm trying to add unique columns on a pivot table created via a <code>ManyToMany</code> association. </p>
  
  <p>I found this <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#annref-uniqueconstraint" rel="nofollow noreferrer">page of the documentation</a> explaining how to generate a database unique constraint on some columns with this example:</p>
  
  <pre class="lang-php prettyprint-override"><code> /**
   * @Entity
   * @Table(name="ecommerce_products",uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "email"})})
   */
  class ECommerceProduct
  {
  }
  </code></pre>
  
  <p>But this only works if I create the pivot table via a third entity and, in my case, I created the pivot table using a <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#manytomany" rel="nofollow noreferrer">ManyToMany</a> relation (in the same fashion as <a href="https://gist.github.com/Ocramius/3121916" rel="nofollow noreferrer">this code</a>).</p>
  
  <p>Is there a way to add unique columns on pivot table while still using <code>ManyToMany</code> or do I need to rely on a third entity?</p>