views:

1233

answers:

1

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.

+8  A: 

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:

Rob Hruska
Thank you! You cannot do m.body.length i have discovered. You have to do SIZE(m.body)But very close
I'll change it. I wasn't sure of the exact HQL, I had just copied what you were using, but with a different GORM method.
Rob Hruska