Skip to content

How to use a triple join in supabase? #1509

Answered by steve-chavez
jarckn asked this question in Questions
Discussion options

You must be logged in to vote

Hi there @jarckn,

I think your model could benefit from a bit of normalization, that way you can avoid duplicates. It will require one more join table.

So IIUC, a player can pick one or more heroes for the match. Then we could have the model like this:

players >- plays -< matches

plays >- picks -< heroes

A plays join table for the M2M relationship between players and matches, and a picks join table for the M2M on plays and heroes.

I want to be able to access the matches a player played and the heroes he picked.

Then you could do that query like this:

  let { data, error } = await supabase
    .from('matches')
    .select('*, plays(player:players(*),heroes(*))');
Click to see result
[…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jarckn
Comment options

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