Grails
›
Grails - user
Search
everywhere
only in this topic
Advanced Search
Problem relationship classes
Classic
List
Threaded
♦
♦
Locked
2 messages
andersonf
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Report Content as Inappropriate
♦
♦
♦
♦
Problem relationship classes
This post has NOT been accepted by the mailing list yet.
Takes a lot of help from friends to solve this problem.
I'm having some problems while implementing on one class two different types of relations to another class.
As an example imagine an Author having a list of written books and then one which is his prefered one.
From the Grails GORM reference page I was able to implement the correct Many-to-Many relationship as follow:
class Author {
static hasMany = [books: Book]
}
class Book {
static belongsTo = Author
static hasMany = [authors : Author]
}
Which is buy the way working perftectly. The problem comes when I want to add the preferedBook relation to the Author class:
class Author {
Book prefered //My prefered book
static hasMany = [books: Book]
}
The problem that happens here is that it was created two new tables from many to many.
I need to be created to link table many to many.
author_books:
author_id
book_id
And I need to have on the table the author has prefered_book_id.
I appreciate this now.
Anderson
bhushan154
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Report Content as Inappropriate
♦
♦
♦
♦
Re: Problem relationship classes
Hi Anderson,
Sorry if I don't understand your requirement correctly but isn't this kind of what you are trying to do
class Author {
static hasMany = [books: Book, preferredBooks: Book]
}
Loading...
Powered by
Nabble
Edit this page