devbd
devbd

Reputation: 431

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

enter image description here

enter image description here

Upvotes: 0

Views: 115

Answers (1)

devbd
devbd

Reputation: 431

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.

Upvotes: 1

Related Questions