Grails Domains - Multiple many to many relationships

Viewed 168

I'm running with grails 3.1.4 and having trouble creating a schema that allows me to tie multiple domain objects to several other domain objects. As an example of what I'm trying to do:

I have three classes. Books, Authors, and ReadingLists.

Authors could have written many books. Books can be written by several authors. Also, ReadingLists are made up of several books and books can be part of multiple readingLists. How should I go about making the domain for this?

I've tried to set them up as follows:

class Author {
    Long id
    String firstName
    String lastName
    static hasMany = [books: Book]
}

class ReadingList {
    Long id
    String name
    static hasMany = [books: Book]
}

class Book {
    Long id
    String title
    Integer pageCount
    static belongsTo = [author: Author, readingList: ReadingList]
    static hasMany = [authors: Author, readingLists: ReadingList]
}

While compiling, I get this error:

No owner defined between domain classes 
[class firstapp.ReadingList] and [class firstapp.Book] in a many-to-many relationship.

I've tried changing my belongsTo value to be the exact same as the hasMany, with the map keys being plural verbs, but that doesn't seem to work either. Any thoughts about how I can accomplish this?

Thanks

1 Answers
Related