Mapping one to many - Mailing list pgsql-novice

From Nabil
Subject Mapping one to many
Date
Msg-id 5B53CC46-9E2C-400D-945E-5AC72F2864C9@kramer-smilko.com
Whole thread Raw
Responses Re: Mapping one to many
List 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.

pgsql-novice by date:

Previous
From: Richard Broersma Jr
Date:
Subject: Re: inputs for pg_get_id() function?
Next
From: Michael Glaesemann
Date:
Subject: Re: Mapping one to many