[PR #30] [MERGED] Bugfix: UoW should properly handle entities of different classes #59

Closed
opened 2026-01-23 11:35:03 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/KeyValueStore/pull/30
Author: @TheDistantSea
Created: 7/24/2015
Status: Merged
Merged: 7/24/2015
Merged by: @beberlei

Base: masterHead: unit-of-work-identity-map-fixes


📝 Commits (1)

  • bcf6d01 Bugfix: UoW now properly handles entities of different classes

📊 Changes

1 file changed (+30 additions, -28 deletions)

View changed files

📝 lib/Doctrine/KeyValueStore/UnitOfWork.php (+30 -28)

📄 Description

An EntityManager is responsible for handling entities of all types and aggregates a single UnitOfWork member for its lifetime.

This means UnitOfWork itself must be able to handle entities of all types, which unfortunately it cannot. The reason is that out of its internal mapping structures, $identityMap uses normalized entity keys as array keys and therefore gets confused in the presence of entities of unrelated classes that have identical normalized primary keys -- for example, unrelated User and Group entities with the same single-column PK id, when the unit of work encounters a User and a Group that happen to also have the same value for id.

This PR fixes the issue by adding another level of mapping based on the entity class name, just like Doctrine's UnitOfWork implementation.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/KeyValueStore/pull/30 **Author:** [@TheDistantSea](https://github.com/TheDistantSea) **Created:** 7/24/2015 **Status:** ✅ Merged **Merged:** 7/24/2015 **Merged by:** [@beberlei](https://github.com/beberlei) **Base:** `master` ← **Head:** `unit-of-work-identity-map-fixes` --- ### 📝 Commits (1) - [`bcf6d01`](https://github.com/doctrine/KeyValueStore/commit/bcf6d01c3f8942fa6f6cf5959e68124e3c82baef) Bugfix: UoW now properly handles entities of different classes ### 📊 Changes **1 file changed** (+30 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `lib/Doctrine/KeyValueStore/UnitOfWork.php` (+30 -28) </details> ### 📄 Description An `EntityManager` is responsible for handling entities of all types and aggregates a single `UnitOfWork` member for its lifetime. This means `UnitOfWork` itself must be able to handle entities of all types, which unfortunately it cannot. The reason is that out of its internal mapping structures, `$identityMap` uses normalized entity keys as array keys and therefore gets confused in the presence of entities of unrelated classes that have identical normalized primary keys -- for example, unrelated `User` and `Group` entities with the same single-column PK `id`, when the unit of work encounters a `User` and a `Group` that happen to also have the same value for `id`. This PR fixes the issue by adding another level of mapping based on the entity class name, just like Doctrine's `UnitOfWork` implementation. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-23 11:35:03 +01:00
admin closed this issue 2026-01-23 11:35:04 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/KeyValueStore#59