【问题标题】:Grails 3.3.0 bidirectional hasMany is not workingGrails 3.3.0 双向 hasMany 不起作用
【发布时间】: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"
        }
    }

【问题讨论】:

    标签: hibernate grails


    【解决方案1】:

    好像是个bug,我在githubhttps://github.com/grails/grails-core/issues/10849提出了一个问题

    类似的讨论见于 https://github.com/grails/grails-core/issues/10796

    希望它对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      相关资源
      最近更新 更多