vault backup: 2025-11-26 15:12:40

This commit is contained in:
Vincent Verbruggen
2025-11-26 15:12:40 +01:00
parent 5d55c88efb
commit dbe8119f52
6 changed files with 107 additions and 9 deletions

View File

@@ -1 +1,15 @@
https://ollieread.com/articles/a-minimal-identity-map-for-laravel-eloquent
https://ollieread.com/articles/a-minimal-identity-map-for-laravel-eloquent
Implementation pattern (not a package) that ensures each database row has a unique representation in memory. Multiple queries for the same row return the identical object instance rather than separate copies.
## Problem Solved
Without an identity map, Eloquent creates multiple instances of the same database row. If you update a User model in one place, changes are not reflected in other places holding a different instance of the same row.
## How It Works
- Static registry stores model instances mapped by class name and primary key
- Hooks capture newly queried models via `newFromBuilder()`
- Freshly created models added via the `created` event
- Deleted models removed via `deleting`/`forceDeleting` events
- Subsequent queries update existing instances rather than creating duplicates
#laravel #eloquent #pattern #identity-map #orm #caching #memory