0

使用 Book 和 Author 域类如下:

class Book { 
    static belongsTo = Author
    static hasMany = [authors:Author]
    String title
}

class Author {
   static hasMany = [books:Book]
   String name
}

我如何找到标题为“Grails”的作者的书?

我试过了,但是没有用(没有方法签名:org.hibernate.collection.PersistentSet.findByTitle() 适用于argumentnt类型:(java.lang.String)值:[Grails]。

Author author = Author.get(1)
def book = author.books.findByTitle("Grails")
4

1 回答 1

1

您可以按如下方式搜索。

作者 author = Author.get(1) def b = Book.find( new Book(title:'grails', author:author) )

有关如何进行查询的信息,请参阅此链接。

于 2009-07-24T16:16:36.707 回答