https://supabase.com/ logo
#help
Title
# help
k

kresimirgalic

05/31/2022, 8:52 PM
hey guys, whats the best solution to make something like this, i will try to explain as much as possible: - user will create company, and inside the company profile he can add employees - employees are basically registered profiles table - inside the company profile, user will have the choice to add members what i tried is to push the uuid to array, but the problem is how to populate those uuid with profile data to show full name, avatar etc i've attached the design so you can get a visual idea, same thing is with benefits, i want to connect benefits with company profile. what would be the best solution?
n

Needle

05/31/2022, 8:52 PM
Hello @kresimirgalic! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! 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.
g

garyaustin

05/31/2022, 8:59 PM
Seems like you might want a company member table instead of an array. That table has company id and profile id as pairs. Then you can use joins/foreign keys to associate profile data with each row found for a company. Using array you could also probably write an sql function to process the array and build up profile information to pass back. I would not try to put info in with your array (with json for instance) as then if it ever changes you have to keep it updated.
n

Needle

05/31/2022, 8:59 PM
kresimirgalic (2022-05-31)
k

kresimirgalic

06/01/2022, 6:44 AM
@Needle so you are suggestion to create a table like company_member which contains a relation to user id and company id, and thats all? can you please give me an example of joins, because i am no experts in sql 🙂 thanks in advance
g

garyaustin

06/01/2022, 2:20 PM
Yes the table would have company_id,user_id columns. With company and user id column referencing (foreign keys) the company and user tables (assuming their primary key is the id). This https://postgrest.org/en/stable/api.html#resource-embedding gives examples on table relationships in PostgREST (which Supabase uses). You can also google Postgres database itself for examples of joins. This link shows how you could get user data "joined" to the result (instead of just returning user_id) in JS https://supabase.com/docs/reference/javascript/select#query-foreign-tables To get all the users for a company you would do a select with a filter on your company_id column and you would get back all users in that company with their joined info.