I want to build a 'Entity' class that can both have childs and parents:
class Entity {
static hasMany [childs: Entity, parents: Entity]
}
But I dont know how to map my data (should I use mappedBy?)
My test:
@Test
void testEntityCanHaveAChild() {
Entityparent = new Entity()
Entitychild = new Entity()
parent.addToChilds(child)
assert parent.childs
assert parent.childs.size() == 1
assert parent.childs.contains(child)
assert child.parents
assert child.parents.size() == 1
assert child.parents.contains(parent)
}
So from Parent I wanna be able to gets all childs and from Child I wanna gets all parents
The only way I found to do it is by adding a many-to-many table between "both table" and to simulate the "auto-relation" like this: