Re:Understanding N + 1 queries problem
by saila on Monday January 02, 2023 @05:50PM
(#34224815)
Using a typical set of Post & Comment models, where Comment has a foreign key to Post, I couldn't figure out how to do this with just a single query in Django. Using prefetch_related, the 2-query version is pretty straightforward:
How would you reduce this to one query using the Django ORM?
[ Parent
| on HN ]