orm icon indicating copy to clipboard operation
orm copied to clipboard

Failing test for setFetchMode(EAGER) that breaks the loaded collection when custom PK type is used

Open janedbal opened this issue 6 months ago • 3 comments

  • 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

janedbal avatar Aug 15 '25 12:08 janedbal

If you have a fix proposal, I can even fix the issue. So far, I believe we need to extract identifiers from those entities and use its DbalType::convertToDatabaseValue to fix it properly.

janedbal avatar Aug 18 '25 10:08 janedbal

There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days. If you want to continue working on it, please leave a comment.

github-actions[bot] avatar Nov 17 '25 03:11 github-actions[bot]

Still valid issue.

janedbal avatar Nov 17 '25 06:11 janedbal