[PR #12130] Failing test for setFetchMode(EAGER) that breaks the loaded collection when custom PK type is used #13498

Open
opened 2026-01-22 16:17:17 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/12130

State: open
Merged: No


  • Using eager setFetchMode breaks fetched collections when certain custom types are used for primary keys.
    • The collection receives 0 items, but is marked as initialized.
  • For int-backed PK types, a PHP Warning is raised from PDO:
    • Object of class CustomId could not be converted to int
  • The core problem is imo that raw entities are being passed to EntityPersister->loadAll
    • This is generally broken in Doctrine ORM when custom PK types are used and one must extract the ids a provide proper ParameterType for those.

Note1: You can simulate the same issue even for string-backed PK types when its __toString() does not 100% match the database value (e.g. using md5 there).
Note2: Originally detected by our extensive testcases in shipmonk/doctrine-entity-preloader

**Original Pull Request:** https://github.com/doctrine/orm/pull/12130 **State:** open **Merged:** No --- - **Using eager `setFetchMode` breaks fetched collections** when certain custom types are used for primary keys. - **The collection receives 0 items, but is marked as initialized**. - For int-backed PK types, a **PHP Warning is raised from PDO**: - `Object of class CustomId could not be converted to int` - The core problem is imo that [raw entities are being passed to EntityPersister->loadAll](https://github.com/doctrine/orm/blob/5a541b8b3a327ab1ea5f93b1615b4ff67a34e109/src/UnitOfWork.php#L2670) - _This is generally broken in Doctrine ORM when custom PK types are used and one must extract the ids a provide proper ParameterType for those._ Note1: You can simulate the same issue even for string-backed PK types when its __toString() does not 100% match the database value (e.g. using md5 there). Note2: Originally detected by our extensive testcases in [shipmonk/doctrine-entity-preloader](https://github.com/shipmonk-rnd/doctrine-entity-preloader/pull/20)
admin added the pull-request label 2026-01-22 16:17:17 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#13498