Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2006
    Posts
    43

    Groups and individuals

    Hi, given the following facts:

    - groups and individuals share a M:N relationship
    - groups can contain other groups; the group to group relationship is also M:N

    how might this be modelled? I thought of using the composite pattern (where individual would be a subclass of group, and group contains multiple groups), but this isn't a composition relationship, because an individual can be a part of many groups (child with many parents). Same with group to group relationships...a subgroup can be a part of many containing groups.

    So the following implied solution doesn't seem good at all:

    - Group to Individual is M:N
    - Group to Group is M:N

    The application code would look totally ugly: to perform an action on a group, first you'd have to search all subgroups recursively, then get all individuals associated with each group, then perform the action on all of the above... (Not to mention the trouble of checking that you're not performing the same action more than once on a given individual, based on the cyclic potential of these relationships...)

    Is it just me, or does that seem really 'un-elegant'? How would you model this? Any insight into this problem would be appreciated.

    Thanks.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    it is un-elegant because of the two many-to-many relationships

    you would model it exactly as you have described --

    group (groupid, ...)

    g2g (parentgroupid, childgroupid)

    individual (individ, ... )

    g2i (groupid, individ)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •