我试图使用addTo *方法,然后findAllBy * 请建议我在这里缺少什么。
请检查图像中的错误。
class Book {
String title
static belongsTo = Author
static hasMany = [authors:Author]
}
class Author {
String name
static hasMany = [fiction: Book, nonFiction: Book]
}
class BookController {
def testBook(){
def fictBook = new Book(title: "IT")
def fictBook2 = new Book(title: "MBA")
def fictBook3 = new Book(title: "DBA")
def nonFictBook = new Book(title: "On Writing: A Memoir of the Craft")
def nonFictBook2 = new Book(title: "Cleaning Codex writer")
def a = new Author(name: "Stephen King")
.addToFiction(fictBook)
.addToNonFiction(nonFictBook)
.save()
//println Book.findAllByAuthors([a])
println Book.withCriteria() {
'in'('authors', [a])
}
render "helllo"
}
}
答案 0 :(得分:1)
由于它似乎是一个错误,我在github https://github.com/grails/grails-core/issues/10849
中提出了一个问题发现了类似的讨论 https://github.com/grails/grails-core/issues/10796
希望它有所帮助。