Mapping one to many

Поиск
Список
Период
Сортировка
От Nabil
Тема Mapping one to many
Дата
Msg-id 5B53CC46-9E2C-400D-945E-5AC72F2864C9@kramer-smilko.com
обсуждение исходный текст
Ответы Re: Mapping one to many  (Michael Glaesemann <grzm@seespotcode.net>)
Список 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 по дате отправления:

Предыдущее
От: Richard Broersma Jr
Дата:
Сообщение: Re: inputs for pg_get_id() function?
Следующее
От: Michael Glaesemann
Дата:
Сообщение: Re: Mapping one to many