Skip to content

more join table examples needed #539

Answered by kiwicopple
eifo asked this question in Questions
Jan 15, 2021 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

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!

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@eytanronen
Comment options

@steve-chavez
Comment options

@eifo
Comment options

@steve-chavez
Comment options

@eifo
Comment options

Answer selected by kiwicopple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants