2009-07-24 3 views
0

및 저자 도메인 클래스의 소유 회원 검색 :다음과 같이 대다 도서와 관계

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

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

가 어떻게 제목 "Grails의"가 저자에 의해 책을 찾을 것 ?

나는이 시도하지만 (방법의 어떠한 서명이 작동하지 않았다 arguemnt 유형에 적용 org.hibernate.collection.PersistentSet.findByTitle()을 (java.lang.String의) 값 :. Grails의]

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

답변

1

다음과 같이 예제를 검색 할 수 있습니다.

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

가 querys 작업을 수행하는 방법에 대한 정보를 원하시면 this link를 참조하십시오. 나는 약간의 보정에 필요한 것을

+0

이입니다. 나는 저자의 인스턴스가 따라서 코드는 다음과 같이됩니다. 작성자 = Author.get (1) def b = Book.find (새 책 (제목 : 'grails', 작성자 : 작성자)) 감사! – byamabe