Hi this is maybe a noob question but I’m not sure ...
# help
k
Hi this is maybe a noob question but I’m not sure how to model a couple tables in my Supabase db. Basic idea is for people to create and join competitions. I’m using a profile table and a competitions table. The competition table would have an array of profiles in it. How would I reference what competitions a profile is enrolled in? Iterating through all competitions for a users profile seems slow. Would a shared table where the user id and the competition ID be best or is there a better way with Supabase?
n
Hello @Kariak! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
t
its a many to many relationship between
profile
and
competition
n
Kariak (2022-04-15)
t
you can have another table that links them both.
competition_signup
this new table has the foriegn key both profile and competition tables.
and probably extra info such as signup date The competition table would have an array of profiles in it. Don't actually make it an array though you can
Copy code
sql
select c.*, (select array_agg(profile_id) FROM competition_signup cs where c.id=cs.cometition_id )
FROM competition c
And for working out the comps that the profile is signed up for is now easy as well.
a
lets say table 1 is for competitions and table 2 is for attendees for the competition table you want to know the user that created it and also give each competition an id example competition_id , user_id, name, category etc table 2 is the attendees competion _id (foreign key), name, age, dob, etc etc (you can even have the user_id as well if they need to sign up
k
Thanks you both, @Ape R Us @tourdownunder. Both these approaches give me a good idea of how to push forward. 🙏
n
Thread was archived by @Kariak. Anyone can send a message to unarchive it.