© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
3 replies
Cheqo

How does supabase retrieve foreign table relationships?

I am using supabase nextjs stripe payments project and I came across this line of code:
  const { data, error } = await supabase
    .from('products')
    .select('*, prices(*)')
    .eq('active', true)
    .eq('prices.active', true)
    .order('metadata->index')
    .order('unit_amount', { foreignTable: 'prices' });
  const { data, error } = await supabase
    .from('products')
    .select('*, prices(*)')
    .eq('active', true)
    .eq('prices.active', true)
    .order('metadata->index')
    .order('unit_amount', { foreignTable: 'prices' });

Everything works, but how does it connect products with matching rows in the prices table? Products table itself has no
prices
prices
column. Prices table do have
product_id
product_id
column, but how does it know automatically what to connect since we only wrote
.select('*, prices(*)')
.select('*, prices(*)')
.

I would have imagined that we had to write something like
connect('prices').where('product_id).eq('id')
connect('prices').where('product_id).eq('id')
, but it seems like it does this automatically?
Screenshot_2022-09-04_at_12.01.57.png
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to retrieve Supabase MCP Server URL?
SupabaseSSupabase / help-and-questions
7mo ago
How to count a joined foreign table?
SupabaseSSupabase / help-and-questions
4y ago
Supabase Foreign Data Wrapper help
SupabaseSSupabase / help-and-questions
5mo ago
how does supabase work
SupabaseSSupabase / help-and-questions
4y ago