I am trying to implement two different types of relationships between two domain classes in Grails.
Consider the following; I have two classes of the domain, the class Author and Book, the author has many books.
class Author{
String name
}
class Book{
String title
static belongsTo = [author:Author]
}
The foregoing describes a very simple relationship between the Author and the Book. But I also want the author to have the concept of a list of favorite books. Ideally, this would be presented as separate for many relationships, describing the same object of the book as a list, and stored as such.
class Author{
String name
static hasMany = [favouriteBooks: Book]
static mapping = {
favouriteBooks joinTable: [name: 'favourite_books',
key: 'author_id']
}
}
class Book{
String title
static belongsTo = [client:Client]
}
, ( ), (favourite_books) . . - , , .
, , , , - .
.