简体   繁体   中英

Grails 3.3.0 bidirectional hasMany is not working

Following the example given in Grails doc

I was trying to use addTo* method, then findAllBy* please suggest what am I missing here.

Please check the error in the images.

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

在此处输入图片说明

在此处输入图片说明

As it seems to be a bug, I raised an issue in github https://github.com/grails/grails-core/issues/10849

Similar kind of discussion is found on https://github.com/grails/grails-core/issues/10796

Hope it helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM