title: How to implement Voting for Grails Domain Classes?
body: <p>I have a Book class and need to implement a yes/no voting functionality. My domain classes look like this:</p>
  
  <pre><code>class Book {
     String title
     static hasMany = [votes: Vote]
  }
  
  class User {
    String name
    static hasMany = [votes: Vote]
  }
  
  class Vote {
    boolean yesVote
    static belongsTo = [user: User, book: Book]
  }
  </code></pre>
  
  <p>What is the best way to implement a voting for the book class. I need the following informations:</p>
  
  <ul>
  <li>What is the average yesVote for a book over all votes (either yes or no)?</li>
  <li>How to check if a specific user has done a vote?</li>
  </ul>
  
  <p>What is the best way to implement the computation of the average yesVote such that the performance does not drop?</p>