how to get access of another table based off foreign key?

while fetching dishes table, i want to fetch the user's name based on the user_id which is common to both the recipes and user_profiles table. i have followed the docs at https://supabase.com/docs/guides/api/joins-and-nesting?language=js&output-format=table and ended up with the following code
const { data } = await client
.from("influencer_dishes")
.select(`name, total_orders, price, user_profiles (user_id, name)`)
const { data } = await client
.from("influencer_dishes")
.select(`name, total_orders, price, user_profiles (user_id, name)`)
but when i check network tab, it returns 400 and error message as follows
Could not find a relationship between 'influencer_dishes' and 'user_profiles' in the schema cache
Could not find a relationship between 'influencer_dishes' and 'user_profiles' in the schema cache
what am i doing wrong?
Querying Joins and Nested tables | Supabase Docs
The Data APIs automatically detect relationships between Postgres tables.
4 Replies
garyaustin
garyaustin2y ago
Is there a foreign key relationship set up between the two tables? Just having the same column name is not sufficient.
Zeeshan
ZeeshanOP2y ago
yes, there is foriegn key relation between the two tables.
garyaustin
garyaustin2y ago
NOTIFY pgrst, 'reload schema' You can try that in the SQL editor to flush the postgrest schema cache. Sometimes if you change relationships or add something after you have accessed the tables that is required. But that is not common. You probably need to show your tables and the foreign key link between them. Your select call looks fine.
Zeeshan
ZeeshanOP2y ago
thank you @garyaustin the relationship was incorrect. fixed that. agree that query is correct.now its working fine! thanks! :supafire:

Did you find this page helpful?