搜索多对多关系的拥有成员

时间:2009-07-24 15:06:15

标签: grails has-many

使用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()适用于arguemnt类型:(java.lang.String)value:[Grails]。

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

1 个答案:

答案 0 :(得分:1)

您可以通过以下示例进行搜索。

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

有关如何查询的信息,请参阅this link

相关问题