Reputation: 5219
I would like to get a list containing the most recent book written by each of a list of given authors. I tried this:
List books = Book.withCriteria {
inList('author', authors)
projections {
groupProperty('author')
max('releaseDate')
}
}
This seems to work but unfortunately instead of a List of Books, this returns a List of Lists, each inner list being like [author, releaseDate].
How can I get it to return a list of the relevant books?
Upvotes: 2
Views: 950
Reputation: 26801
I'd use HQL for this and use a subquery, something like:
Book.executeQuery("""
from Book as book
where book.id in (
select id from Book b group by b.author order by b.releaseDate desc
)
""")
Upvotes: 2