1

So I'm learning Supabase, but I got stuck on a query. I reproduced this docs example: https://supabase.com/docs/reference/javascript/select, with the example "Query referenced tables through a join table". I added the example data source in the SQL Editor and created those tables.

I tested it with the example query and it gave the expected reponse:

const { data, error } = await supabase
  .from('users')
  .select(`
    name,
    teams (
      name
    )
  `)

However, when I added a new column (trainer_id, which is a foreign key to the users.id) in the teams table, that same query returns null.

Why does it return null if a foreign key is added? Should I change my query? The goal is to get the exact same response as in the example.

1
  • can you add the create table for both tables, it seems that you have the foreign key wrong Commented Aug 3, 2024 at 9:32

1 Answer 1

1

So I found the answer, it was because there were two relationships after I added a foreign key in the poules table.

Answer:

const { data, error } = await supabase.from('users').select(`
  name,
  teams!users_teams (
    name
  )
`);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.