What is the difference between 'Eager Loading' and 'Lazy Loading' in an ORM (like Eloquent or Doctrine), and how does it affect the N+1 query problem?
Last updated
Lazy loading queries a relation only on first access: convenient and low-memory, but inside a loop it causes N+1 queries.
Eager loading fetches relations up front in one batched query, collapsing N+1 to a constant count.
Eager loading's risk is over-fetching unused data, so load only the relations you'll actually use.
- https://en.wikipedia.org/wiki/PHP
- https://lemon.io/for-developers/php-developer-jobs/
- https://lan-portal.uob.edu.ly/visit/BOOK/529X432U02/modern-php_new__features_and_good-practices.pdf
- https://lan-portal.uob.edu.ly/upload/MD/D57953S372/modern-php__new_features_and__good__practices.pdf
- https://news.ycombinator.com/item?id=30786927
- https://kvnc-inc.medium.com/solid-principles-in-php-1c41069e9af6
- https://www.shkodenko.com/
- https://confoo.ca/en/2024/sessions