A Group
instance can contain Person
instances or other Group
instances. I want to use the Ancestry gem to mirror a hierarchy, but Ancestry does not seem to work with two different models. I don't want to use Single Table Inheritance on Person
and Model
because they are conceptually different.
What is the best way to go about modeling this requirement? I am willing to build my own hierarchy using many-to-many or other types of associations, but I am not sure how to make the two models (Person
and Group
) play nice with each other.
Thank you.
You can easily set a hierarchy on the Group class (using whatever suits you for single-model hierarchies) and then add a one-to-many association between Groups and Users:
You will have
If you really need the group to have either users or subgroups but not both, use a validation rule.