开发者

Return full domain object from Grails / GORM projection

开发者 https://www.devze.com 2023-02-22 12:40 出处:网络
I would like to get a list containing the most recent book written by each of a list of given authors. I tried this:

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

精彩评论

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