开发者

database relations grouping items

开发者 https://www.devze.com 2023-02-03 22:58 出处:网络
Hi I\'m creating an online tool allowing users to add items of clothing to their account. I want to allow users to group these items but am unsure when it comes to the database relationships.

Hi I'm creating an online tool allowing users to add items of clothing to their account. I want to allow users to group these items but am unsure when it comes to the database relationships.

Items are added by users;

Multiple items should then be able to be grouped together;

A single item should be able to be in more than one group.

Before the grouping feature I had one table for users and one table for items, linked via a primary/foreign key. Then to get items from a specific user I simply joined the two tables and selected entries by user_id.

I'm unsure how I should go about implementing the groups feature

Should I have a table for groups and how should they relate ?

I'm really new to database relations but if I have a table ca开发者_StackOverflow社区lled groups, how can it have an array of items as an entry? or how can an item have an array of groups that it belongs to ?

any help would be brilliant


Tables

USER
-----
userID (pk)  


GROUP
------
groupID  (pk)  
userID   (fk)



GROUP_ITEMS
---------
groupID (pk)  
itemID  (pk)  


ITEM
----
ItemID (pk)  

Be aware the "GROUP" will most likely be a reserved/keyword so you may want to rename it.

0

精彩评论

暂无评论...
验证码 换一张
取 消