Below is a code where I am trying to perform a join operation. I have a table citizen which has a foreign key location_id from table location. Now i want to retrieve the the name of location when of the citizen using the Location Id:
@app.get("/join")
async def get_citizens_location():
response = supabase.table('citizens').select('firstname').execute()
return response
How do I solve this, are there alternative?
@app.get("/join")
async def get_citizens_location():
response = supabase.table('citizens').select('firstname','location:name').leftJoin('citizen:location_id','location:id').execute()
return response
I have tried this so far but it looks like Supabase does not have left join method or class
You can join tables easily in supabase with the help of foreign keys.
What I have inferred from your question that, you have two tables
citizen
andlocation
with a foreign keylocation_id
in the tablecitizen
.To join these two tables, you can use the following code (assuming that you want all matched data from these two tables):
Reference to the documentation