Skip to content
Latchkey

What Is Eager Loading?

Eager loading retrieves an object and its specified related records together in one query or a small fixed number of queries. The associations are loaded before they are accessed, rather than on demand. It is the standard remedy for the N+1 query problem caused by lazy loading in a loop.

Why it matters

Pulling related rows in one pass collapses many small queries into a single efficient one. Used wrongly it can over-fetch data, so it trades extra payload for fewer round trips.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →