mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Changes to entities with readonly identifier are not persisted #7585
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @adrav on GitHub (Jan 1, 2026).
Problem when using readonly property for ID in Entity
Summary
When using a
readonlyproperty for the identifier (id) in an entity, Doctrine fails to properly manage entity state. After flushing changes to a related entity (updatingHouse::citythrough aHouseFloorreference), subsequent queries return stale data: theHouseentity is reloaded with its previous state instead of the updated one. Data is not persisted to the database.This issue does not occur in
doctrine-bundle2.18.2 and disappears if thereadonlymodifier is removed from the entity ID property, indicating a regression in how Doctrine handles entities withreadonlyidentifiers.composer:
How to reproduce
I have two entites:
House.php
HouseFloor.php
And simple controller:
Then reproduce as below:
If you remove readonly property from House entity it works fine.
Expected behavior:
Modifying a managed entity and calling
flush()should result in an UPDATE statement and persisted changes in the database.Actual behavior:
With a
readonlyidentifier, Doctrine does not detect the entity as dirty and silently skips persisting the change.Workaround
This issue does not occur in
doctrine-bundle2.18.2 and disappears if thereadonlymodifier is removed from the ID property, indicating a regression in change-tracking when entities use PHPreadonlyidentifiers.Downgrade the doctrine-bundle package:
Then it works fine with the readonly property on $id field.
@stof commented on GitHub (Jan 3, 2026):
This is much more likely to be related to versions of the orm than to the version of the bundle (downgrading the bundle might force a change of version of the ORM as well)