select_related for Foreign Keys
JOIN related rows in one query.
Meet select_related
select_related tells Django to fetch related rows up front in the same query, so loops stop firing extra trips. ⚡
It Uses a JOIN
Under the hood it adds a SQL JOIN, pulling the parent and its related row together in one efficient round trip.
All lessons in this course
- Spotting the N+1 Problem
- select_related for Foreign Keys
- prefetch_related for M2M
- Profiling with Debug Toolbar