I'm trying to define a tree structure in GORM. Here is my model:
class Tree {
String name
Level rootLevel
static hasOne = [rootLevel: Level]
static hasMany = [levels: Level]
static mappedBy = [levels:"parentTree"]
}
class Level {
String name
Tree parentTree
Level parentLevel
Set subLevels
static belongsTo = [parentTree: Tree]
static hasMany = [subLevels: Level]
}
Insertion seems to work fine, but when I can't load a Tree with many levels and sublevels.
I guess I missed something in the relations:
- the Tree should have a reference to the rootLevel (and optionally to all sublevels)
- a Level should have a reference to its parent level, its sublevels and the global parent Tree
Could you point me out the right direction to get a tree structure like this ?
Thanks
以上就是Tree structure in GORM (grails)的详细内容,更多请关注web前端其它相关文章!