Trying to understand relationships in supabase
Hey
I am trying to set up a few tables for my database, and add data.
It is for a workout api... and I am creating the following tables:
actions
id - code - name - description - updated_at - created_at
joints
id - code - name - latinName - updated_at - created_at
directions
id - code - name - description - updated_at - created_at
planes
id - code - name - description - updated_at - created_at
Every joint have actions which is movement. I have created a relation table for that
joint_actions
id - action_code (fk) - join_code (fk) - created_at - updated_at
The goal is that I want all the actions to come when i query a joint for example. Can i set this up in supabase or does this need to be done in the code?!
6 Replies
https://supabase.com/docs/guides/database/joins-and-nesting this page might be helpful but in essence the APIs can detect foreign key relationships
Querying Joins and Nested tables | Supabase Docs
The Data APIs automatically detect relationships between Postgres tables.
will still require some code setup though
I use google arc as a CMS for now.
Do you know if I can use the IDs in the columns then just import it?!
I am just trying to set up the DB with som data for now and make it easy to change if mistakes are made in the beginning
hmm, what exactly do you want. What is the input/output you're looking for
After som research, my questions isn’t valid :p I found a way forward.
But I was wondering.
If I create a table in Google Sheets and add the foreign key IDs in the cells (pointing to another table), then export it as a CSV and import it into Supabase, will Supabase automatically create the relationship between the tables in the new table? Or do I need to set up the foreign key constraint manually after import?
try importing it, i think it should work as before i remeber updating a row value that has a foreign id on another table and supabase would complain if that id does not exist in said table so it must be tracking these things