How to implement Voting for Grails Domain Classes?

Posted by userWebMobile on Stack Overflow See other posts from Stack Overflow or by userWebMobile
Published on 2012-11-05T22:31:23Z Indexed on 2012/11/05 23:00 UTC
Read the original article Hit count: 229

Filed under:
|
|
|
|

I have a Book class and need to implement a yes/no voting functionality. My domain classes look like this:

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]
}

What is the best way to implement a voting for the book class. I need the following informations:

  • What is the average yesVote for a book over all votes (either yes or no)?
  • How to check if a specific user has done a vote?

What is the best way to implement the computation of the average yesVote such that the performance does not drop?

© Stack Overflow or respective owner

Related posts about grails

Related posts about frameworks