Reputation: 36008
I want to run a sql query similar to:
SELECT count(*) from WORDS where wordId in (4,5,6)
How can I write this in Gorm? I know grails has countBy*
but I can't pass multiple values like [4,5,6]
into it.
should I just use execute
?
Upvotes: 0
Views: 1900
Reputation: 50285
You can also use rowCount
in the projections which counts the number of rows of the result. Note id
as Long
Words.createCriteria().get {
'in'('id', [4,5,6]*.toLong()) //or [4L, 5L, 6L]
projections {
rowCount()
}
}
Upvotes: 1
Reputation:
You can use projections.
Words.createCriteria().get {
'in'('id', [4,5,6])
projections {
count('id')
}
}
Upvotes: 0