Mapping one to many

From: Nabil <Nabil(at)kramer-smilko(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Mapping one to many
Date: 2007-06-13 15:05:25
Message-ID: 5B53CC46-9E2C-400D-945E-5AC72F2864C9@kramer-smilko.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Ok this is a very simple problem but for some reason I'm suffering
from brain freeze. I have two tables Users and Groups. A user can be
a member of many different groups. What I was thinking of doing is
creating a column called groups in users of type int[] that contains
the ids of the groups the user is a member of. I want to make sure
the group exists. The problem is I cant have Users.groups reference
Groups.id. Is there some kind of check I can do? If so what would
happen if I delete a group that has members in it? One other way I
though about was having a user_group_mapping table so that would have
something like user_id that references Users.id and group_id that
references Groups.id and when I want to figure out what groups a user
is a member of I would do "SELECT group_id FROM user_group_mapping
WHERE user_id=(the id I need)" but that seems kind of messy. I'm open
to any suggestions. Thanks in advance to every and any one who help.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Glaesemann 2007-06-13 15:49:44 Re: Mapping one to many
Previous Message Richard Broersma Jr 2007-06-13 03:56:39 Re: inputs for pg_get_id() function?