HandbookII the ForumRelations between tables
IIthe Forum, The shape of an appRelations between tables
In plain words
A relation links tables by storing one row's id inside another, so an order can point to its restaurant and each item can point back to its order.
Where you see it
In Supabase's Table Editor, QuickBite's orders table has a restaurant_id column holding numbers like 7. That column is a foreign key: 7 is the id of a row in the restaurants table.
What goes wrong
- Copying data instead of linking it
Storing the restaurant's name on every order means a rename leaves 4,000 orders with the old one. Store restaurant_id and look the name up.
- No foreign key, so orphans pile up
Without references, you can delete a member and leave their posts pointing at nobody. The feed then crashes trying to read author.name.
- A cascade nobody expected
on delete cascade in the wrong place means deleting one restaurant silently removes every order ever placed there, including the ones your accountant needs.
What to tell your agent
Quick check
Sign in to earn +10 XP for itA QuickBite restaurant changes its name, but the orders page still shows the old one. Why?