more join table examples needed #539
-
I could not get around the documentation to convert the following join example with aliases, I could create a view / function of course but I'm trying to wrap my head around supabase syntax, any help pls, the following is the function I'm trying to convert using pg driver: const {rows} = await db.query( |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I'll trim your SQL a bit so it's more readable, but you should be able to change this: select *
from companies c
join countries cou on cou.id = c.country_id
join company_user cu on cu.company_id = c.id
where c.id = "XXX" and cu.user_id = "YYY" to this: const { data, error } = supabase
.from('companies')
.select(`
*,
countries(*),
company_user(*)
`)
.eq('id', companyId)
.eq('company_user.id', user_id) The relationships should be auto-detected by PostgREST. Let me know if that doesn't work! |
Beta Was this translation helpful? Give feedback.
I'll trim your SQL a bit so it's more readable, but you should be able to change this:
to this:
The relationships should be auto-detected by PostgREST. Let me know if that doesn't work!