What Is Lazy Loading in Data Access?
Lazy loading in data access is a strategy where related records are not retrieved until code first reads them. Accessing an unloaded association triggers a query on the spot. It saves work when associations go unused but can hide expensive queries behind ordinary property access.
Why it matters
Lazy loading keeps initial queries lean, yet careless use inside loops is a classic source of the N+1 query problem. Knowing when data loads helps you avoid surprise round trips.
Related guides
What Is Eager Loading?Eager loading fetches related data upfront in a single combined query, so associations are already available…
What Is an N+1 Query?An N+1 query is a performance problem where fetching a list runs one query, then one extra query per row to l…
What Is the Active Record Pattern?The active record pattern gives each object both its data and the methods to load, save, and delete itself, c…