mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Null-object error in spl_object_hash() when loading associations with association-keys #6811
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 @AlexanderDahmen on GitHub (Aug 18, 2021).
Bug Report
Summary
In an entity with foreign identity (using
association-key="true"), having a many-to-many association withfetch="EAGER"results in the following error message:Current behavior
When using lazy many-to-one association mappings with Entity classes that contain eager many-to-many associations, loading these entities will cause an internal error with the EntityManager trying to hash an object.
A screenshot of the partial stack-trace is attached:

How to reproduce
Given a table schema like:
Entity classes are defined as:
With an ORM XML mapping like:
Trying to initialize the collection
First::$secondby accessing elements will result in the above mentioned error.As far as I can tell, this is caused by the EntityManager trying to hash the key of
Second, which is$first, but the association is not yet loaded when initializing the$thirdCollection.(This is an anonymized transcript of the production code causing the issue, if the reproduction does not work, please tell and I will revise the example.)
Expected behavior
The expectation is for the foreign collection to be loaded correctly.
Currently, only
fetch="LAZY"works for loading the associations.@greg0ire commented on GitHub (Aug 18, 2021):
Possible next steps:
$fieldinBasicEntityPersisteron line 1011@greg0ire commented on GitHub (Aug 18, 2021):
@AlexanderDahmen what piece of code should I write inside
testIssueto reproduce the issue:e6976436b3? Please send a PR to my fork.@AlexanderDahmen commented on GitHub (Aug 18, 2021):
@greg0ire Created a fork and pull request with a test case reproducing the error: https://github.com/greg0ire/doctrine-orm/pull/4
Thank you for looking into this.
@greg0ire commented on GitHub (Aug 19, 2021):
I pushed another commit with a better error handling. It reveals that the field with an issue is
Second::$first. I think this happens because there is an attempt to load$thirdwhile assuming that$firstwas loaded, well, first.@Feolius commented on GitHub (Apr 27, 2022):
I have created a pull request https://github.com/doctrine/orm/pull/9680 to solve this issue.