Skip to content

Eager loading

Eager loading is an ORM technique that fetches related records together with the parent query instead of one by one.

Eager loading is an ORM (object-relational mapper) technique that loads related records up front, together with the parent records, instead of fetching them one at a time when your code first touches them. The opposite is lazy loading.

Laravel’s Eloquent documentation describes it as the remedy for the N+1 query problem. Reading each book’s author in a loop runs one query per book, but Book::with('author')->get() runs two queries: one for the books and one for all their authors using a WHERE id IN list.

Other ORMs have equivalents under different names, so check your framework’s documentation. If SQLEye flags an N+1 query group, the shape of the repeated query usually tells you which relationship to load eagerly. See N+1 detection.

← Glossary · Also available as Markdown.

SQLEye is developed and maintained by CodeROG. This page is also available as Markdown.