Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count in Grails/Hibernate: Message.countBy

How do I count the number of messages where my body length is between 0 and 25 characters long?

Message.countBy('from Message m where m.body.length <= 25')

Unfortunately for me, countBy does not take a string parameter.

like image 304
user57660 Avatar asked Jan 21 '09 20:01

user57660


1 Answers

Looking at the dynamic method reference, the best you can probably do is use executeQuery instead of count*:

Message.executeQuery('select count(m) from Message m where SIZE(m.body) < 25')

EDIT: Here are a couple of links that might help with writing/executing the query:

  • HQL Reference
  • Grails Domain Class Dynamic Method Reference
like image 89
Rob Hruska Avatar answered Oct 14 '22 10:10

Rob Hruska