开发者

Return full domain object from Grails / GORM projection

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(开发者_如何学Go'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?


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
     )
""")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜