title: Grails GORM Constraint
body: <p>Given the following two domains:</p>
  
  <pre><code>class Follows {
      User followee
      ...
      static belongsTo = [follower: User]
  }
  
  class User {
      String name
      String lastName
      ...
      static hasMany = [ follows: Follows ]
      static mappedBy = [ follows: 'follower' ]
  }
  </code></pre>
  
  <p>Which creates the following table:</p>
  
  <pre><code>+------+-------------+-------------+
  |  id  | follower_id | followee_id |
  +------+-------------+-------------+
  | 1    | 1           | 3           |
  | 2    | 3           | 2           |
  | 3    | 2           | 1           |
  +------+-------------+-------------+
  </code></pre>
  
  <p>Is there a way through <em>contraints</em> to prevent duplicates of <em>follower</em> - <em>followee</em>? I'm trying to prevent both directions, like, User Id 3 should not be able to <em>follow</em> the User ID 1 if the User ID 1 is already following the User ID 3.</p>
  
  <p><strong>In other words, this is what I'm trying to prevent:</strong></p>
  
  <pre><code>+------+-------------+-------------+
  |  id  | follower_id | followee_id |
  +------+-------------+-------------+
  | 1    | 1           | 3           |
  | 2    | 3           | 1           |
  +------+-------------+-------------+
  </code></pre>
  
  <p>I know I may be able of querying the database before insertion to check if User 1 is following 3 (or the other way around) and if true cancel the insertion, but I'm trying to avoid hitting the DB twice per <em>follow</em> operation.</p>
  
  <p>Cheers and thanks for all your answers!</p>