SQL to Supabase query
Apologies if this has already been answered. I could not work out how to do this.
I'm trying to query a category by its slug and return the associated articles in the category. I have a join table categories_articles that contains an id (id of the category) and item (id of the article)
The following SQL query works:
Any tips for how to do this with the Supabase API?
4 Replies
The API can automatically detect joins thru a join table as long as both fk's are part of the primary key.
So
.select('*,categories(*)')
Is the basic join relationship.
Then you can filter with something like .eq('categories.slug','the-slug')Thanks for the help but it didn't work, most likely due to the FKs not being part of the primary key.
I'm using Directus as the visual layer to Supabase. So it seems the way Directus creates M2M and M2A relationships is not the way Supabase would like them to be set.
It does not have a way to force the primary keys?
Anyone else with the same question, I solved it with:
Thanks for your help Gary