mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Meta data missing when using DiscriminatorMap #6420
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 @pmishev on GitHub (Mar 3, 2020).
Bug Report
Summary
When using a DiscriminatorMap, is seems metadata in entity manager is not being loaded for entities.
Current behavior
How to reproduce
I have different types of notes using a single table using DiscriminatorMap:
Then there's a link entity:
And I have a basic CRUD for creating a new "JournalistPolicy":
Inside the JournalistPolicyType::buildForm() :
Submitting that form in PHP 7.3 gives an error:
This happens because when the
UniqueEntityValidatorinsymfony-bridgetries to validate the entity, it tries to build a select query for the selected journalist and a note that does not yet have an id.In this line: https://github.com/doctrine/orm/blob/2.7/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L1943, it basically converts the entity to a
nullwhen it has the metadata for it.When there is no metadata for the entity at that point, the entity object is bound to the PDO query as it is.
So, when PDO::execute() is called, it tries to convert an object to an integer, which throws an expected exception.
In php7.1, this problem went unnoticed, because PDO works differently there - apparently the object was first being converted to string and then to int, so given that there was a __toString() method, the result was
null, which was just fine.I am posting this issue here, because to me the main problem lies in the fact that the metadata for the JournalistPolicy object is missing in the entity manager and it doesn't even tries to retrieve it.
I suspect it is missing because of using a DiscriminatorMap, however I can't figure out how and when metadata is being populated, in order to suggest a fix
Expected behavior
The metadata for JournalistPolicy to exist in the entity manager, so the code enters tha
if: https://github.com/doctrine/orm/blob/2.7/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L1943 and the object is transformed to anull