【发布时间】:2017-11-06 13:33:29
【问题描述】:
按照Grails doc中给出的示例
我尝试使用 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"
}
}
【问题讨论】: