Grails - multiple objects database relationship
I have a non-Grails specific question, but I intend to implement it with it. Anyway. I would like to ha开发者_开发问答ve a One-to-Many domain class relationship, but I would like the Many part to be of several different types.
For instance:
A domain Class Man
would have several Friends
(this is our 1 to Many relationship), but the Friends bit could be another Man
with its particular sets of methods and attribute, or a Dog
, or a Monster
, etc.
I have browsed the web but do not know how to name properly what i am searching for. Any help greatly appreciated
Can you try this? I am not sure %100 but you should do something like this. You need an interface for inheritance.
interface Alive{
//just definition
}
class Friend implements Alive {
//definition
}
class Pet implements Alive{
//definition
}
Person{
static hasMany = [ alives: Alive]
}
精彩评论