2011-04-04 30 views
2

我想得到一个列表,其中包含由给定作者列表中的每一个书写的最新书。我尝试这样做:从Grails/GORM投影中返回完整的域对象

List books = Book.withCriteria { 
    inList('author', authors) 
    projections { 
    groupProperty('author') 
    max('releaseDate') 
    } 
} 

这似乎是工作,但不幸的是,而不是图书的清单,这将返回列表的列表,每个内部列表是象[作者,RELEASEDATE。

我怎样才能得到它返回相关书籍的清单?

回答

2

我会使用HQL,这和使用子查询,像这样:

Book.executeQuery(""" 
    from Book as book 
    where book.id in (
     select id from Book b group by b.author order by b.releaseDate desc 
    ) 
""")