开发者

Grails - multiple objects database relationship

开发者 https://www.devze.com 2023-04-13 07:56 出处:网络
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 o

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]
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号