New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
My endpoint returns a list of orders with their customers, and it works, but the database log shows one extra query per order.
What you'll have at the end
The same endpoint response using 2 queries total instead of one per row, confirmed by counting queries in the log
You need
A working endpoint that already queries a list of orders through SQLAlchemy and returns each one with its customer's name, plus the ability to turn on your own database connection's query logging.
Not covered
An N+1 coming from a raw SQL loop instead of the ORM's own relationship loading; that needs a different fix than a loader option.
Leans on
Checked 18 Aug 2026
Part of the ORM and Database Abstraction Tools cookbook