一对多的关系是:
class Author {
static hasMany = [books: Book]
String name
}
如果我们不在Book中指定belongsTo,即
class Book {
String title
}
如何使用给定的书籍过滤作者。
def books=[book1,book2,book3]
答案 0 :(得分:0)
您可以使用create criteria来获取作者:
def bookList = //some book list
def authors = Author.createCriteria().list {
books {
'in'('title', bookList*.title)
}
}*.name
println "Authors = ${authors}"
答案 1 :(得分:0)
我更喜欢HQL。
Author.executeQuery("select a from Author a join a.books as b where b in (:bookList)", [booklist: books])