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' });

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

I would have imagined that we had to write something like connect('prices').where('product_id).eq('id'), but it seems like it does this automatically?
Screenshot_2022-09-04_at_12.01.57.png
Was this page helpful?