Skip to content

Conversation

janedbal
Copy link
Contributor

  • 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

setFetchMode breaks fetched collections when custom types are used
for primary keys. The collection loads 0 items instead of the
expected count and marks itself as initialized, making it appear
empty. Additionally, a PHP Warning is raised from PDO:
"Object of class CustomId could not be converted to int"

This test demonstrates the issue by creating a Category entity with
a wrapped integer primary key using a custom DBAL type. When using
FETCH_EAGER mode, the children collection fails to load properly.
@janedbal
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant