title: Symfony2 Many-to-many unique constraint
body: <p>Let's say I have a Thing entity, a Group entity, and a Year entity. Each Group belongs to a Year. However, Things have no relationship with Years. There is a many-to-many relationship between Things and Groups (a Group is made of several Things, and a Thing can belong to several Groups).</p>
  
  <pre><code>My\MainBundle\Entity\Group:
      type: entity
      manyToOne:
          year:
              targetEntity: Year
      manyToMany:
          things:
              targetEntity: Thing
              joinTable:
                  name: groups_things
                  joinColumns:
                      group_id:
                          referencedColumnName: id
                  inverseJoinColumns:
                      thing_id:
                          referencedColumnName: id
  </code></pre>
  
  <p>What I would like to do is make sure that, <strong>for a given year</strong>, a group is unique. That is, if, for 2014, I have a Group that has Things 1, 2 and 3, I wan't to prevent the user from creating another Group with the same Year, and the same Things. However, creating another group with the same Things for another year is fine.</p>
  
  <p>I'm not sure what to put in my <code>validation.yml</code> file, to prevent the user from creating several Groups with the same Things for the same Year.</p>
  
  <p>I've tried:</p>
  
  <pre><code>My\MainBundle\Entity\Group:
      constraints:
          - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
              fields: [year, things]
              message: This group already exists.
  </code></pre>
  
  <p>but it doesn't work. I get an exception:</p>
  
  <blockquote>
    <p>ContextErrorException: Notice: Undefined index: joinColumns in /var/www/vhosts/myhost.local/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1665</p>
  </blockquote>