mardi 20 octobre 2015

Database Design: User can be part of many lists, and lists can be associated with multiple users

So I'm trying to work on a small app that would allow you to have a grocery list that can be edited by multiple people via their mobile phone. So I'm trying to design the database I will use on the backend. I'm having trouble figuring out how to relate all the tables. User will be able to be apart of multiple lists, and each list will be accessible by multiple people. ( I believe this is called a many-to-many relationship?) So far my tables look as follows:

User(id, name)
List(id, Name)
List_item(id, List_id(key), name, amount)

The list to list_item ID relationship is easy enough, but how do I go about modelling the relationship between Users and Lists? Do I need a separate join table:

User-to-List(User ID,List ID)

I'm trying to come up with the most efficient structure as possible, Thanks!

Edit: Only the user needs to know about all the lists he is associated with, the list doesn't need to keep track which user are associated with it. At least for the initial app!

Aucun commentaire:

Enregistrer un commentaire