Question

Maybe it's because I don't understand how to search for the right verbiage, but I'm having difficulty understanding how to attach multiple users to a table with multiple columns.

Here is what I'm attempting to do:

table name: user   

   user_id    user_name
   1          abc
   2          xyz  
   3          pqr
   4          new  


table2 name : brackets

    id             user_id    bracket_name
    1              4,2        bracket_1
    2              4,3,1      bracket_2 
    3              2,1        bracket_3
    4              3,4,2      bracket_4

-- OR --

table name: user   

   user_id    user_name  brackets_id
   1          abc        2,3
   2          xyz        1,3,4
   3          pqr        2,4
   4          new        1,2,4


table2 name : brackets

    brackets_id    user_id    bracket_name
    1              4,2        bracket_1
    2              4,3,1      bracket_2 
    3              2,1        bracket_3
    4              3,4,2      bracket_4

I'm using nodejs and sequalize as my ORM and understand enough to read, write, delete and update to these tables, but when it comes to organizing my data, I'm completely lost!

Is it possible to add an array to MYSQL with the user ID's or the brackets that the user is allowed to access? The bracket are generated by a user and then they can invite their friends to join a bracket. Users can join multiple brackets and join other brackets as users.

Any guidance would be very helpful!

Was it helpful?

Solution

I think a Junction Table would simplify this for you: http://en.wikipedia.org/wiki/Junction_table

It would look something like:

table name: user   

user_id    user_name
1          abc       
2          xyz        
3          pqr        
4          new        


table2 name : brackets

brackets_id        bracket_name
1                  bracket_1
2                  bracket_2 
3                  bracket_3
4                  bracket_4

table3 your junction table:

user_id     brackets_id      
1           2
1           3
2           1
2           3
2           4

etc.etc.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top