Grails 3.3.0双向hasMany不工作

时间:2017-11-06 13:33:29

标签: hibernate grails

按照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"
        }
    }

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

由于它似乎是一个错误,我在github https://github.com/grails/grails-core/issues/10849

中提出了一个问题

发现了类似的讨论 https://github.com/grails/grails-core/issues/10796

希望它有所帮助。