Skip to content

ORM 4 should not set IDs of removed entities to null anymore #12457

Description

@beberlei

We have regular problems in the reflection code with setting null of ids on remove since readonly and property hooks were introduced into PHP. See #12401 for a recent example.

Since that is just a convention, we could modify the ORM to not unset these properties to null aynmore. Because IDs cannot/shouldn't be reused anyways.

Users would only need to be careful with merging the removed entities back into the UoW as that behavior would change (ID signals that a row exists on merge). So that is a BC break.

In 3.x introduce a Configuration flag onRemoveEntitySetIdentifierNull which defaults to true (current behavior).
Deprecation is thrown once if flag is true during construction of the UnitOfWork.

Flag is checked here to disable setting null: https://github.com/doctrine/orm/blob/3.6.x/src/UnitOfWork.php#L1184

When merged up to 4.x we can make the flag a no-op, remove the code in UnitOfWork. Potentially also remove a lot of code in the PRopertyAccessors that handle this case (readonly, propertyhooks).

This probably needs a documentation update. Maybe AI can help with locating the documentation places and also to find out of the linked UnitOfWork code is the only case that needs to be adressed or if there are others.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions