title: Unique constraint in Grails
body: <p>Assuming i have the following grail domain entities:</p>
  
  <pre><code>class A { ... }
  
  class B { ... }
  </code></pre>
  
  <p>In a third entity i have a one to many relationship as follows:</p>
  
  <pre><code>class C {
      static belongsTo = [a: A, b: B]
  
      static constraints {
          a unique: 'b'
      }
  }
  </code></pre>
  
  <p>Is it possible in grails to define a unique relationship based on both properties (<code>a</code> and <code>b</code>) in class <code>C</code>, so no two <code>C</code> instances may be created having the same combination of <code>a</code> and <code>b</code>?</p>
  
  <p>EDIT: My test case has as follows:</p>
  
  <pre><code>void testCompositeUniqueConstraint() {
      A a = // ...
      B b = // ...
      C existing = // ...
      existing.a = a
      existing.b = b
      mockForConstraintsTests(C, [existing])
  
      C c = // ...
      c.a = a
      c.b = b
  
      assertFalse c.validate()
  }
  </code></pre>
  
  <p>On my test class i have included the <code>@Mock([A, B])</code> annotation. I would expect this test to fail but it passes.</p>