Grails 1.1.1 Goovy 1.5.7

Inside a relationship such this:

Author 1 -- n Book n -- 1 Writer

Defined in Grails:

class Author 

class Book Writer writer

  static constraints = writer(nullable: true)


class Writer title

  static hasMany = [books: Book]

  static constraints = 

I wish to load a magazine using the values of Writer and Author. After i obtain a Book using the query:

def book2 = Book.findAllByAuthor(author)

I recieve the response using the autor assosiated however the writer have only the id and title class within the other query:

def book3 = Book.findAllByPublisher(writer)

I retrieve me the inverse result,i've it using the writer data however the author have only the id and also the class title.

Where's the mistake within the defined model ? o there's a mistake in the manner to complete the queries ?


I want the best way to retrieve the values just with the query such as this:

def book2 = Book.findAllByAuthor(author, [fetch:[writer:'eager']])

In that one I'm able to manage the need for writer.

Question: If writer were built with a hasmany or Domain related, obtaining the book I am in a position to browse the characteristics?

Thanks. Thanks.

Lazy fetching can be used automatically with gorm associations. If you wish to enable eager fetching, you are able to customize the ORM DSL with the addition of the next mappings block for your Author domain class:

static mapping = 

or you might alter the fetch mode within the domain object with the addition of following code after your books relationship is determined.

static fetchMode = [books:"eager"]

Doing exactly the same for your Writer domain object should permit you to accomplish what you would like. You need to do desire to be careful from the consequence that you might load more data than you want to.

Should not the get() method return what you're searching for? Example: def book2 = Book.get(author)