If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Groups and individuals

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-04-06, 01:26
vk101 vk101 is offline
Registered User
 
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.
Reply With Quote
  #2 (permalink)  
Old 08-04-06, 07:19
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On