mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Error on entity clone for MappedSuperclass fields #5075
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 @betd-claumond on GitHub (Apr 1, 2016).
Originally assigned to: @Ocramius on GitHub.
Hello,
We get an error on cloning entity proxy following an upgrade from Doctrine 2.3 to 2.4 (but maybe relevant for 2.5 too).
The error is that fields declared as private on a MappedSuperClass are not cloned when a clone is done on a proxy entity of child class, only the protected fields of the MappedSuperClass are cloned.
This is a breaking change for us because it is only partially cloning entity and could have cause loss of data.
The cause is the usage of ClassMetadataInfo->getReflectionClass()->getProperties() rather than ClassMetadataInfo->reflFields in the cloning process.
I didn't find any existing issue or documentation about that, is it a known issue ?
Is there a clean solution existing to this issue please ?
Below the context information, the code analyse and the workaround solution.
Thanks in advance for your feedback on this issue.
Best regards,
Christophe
Context
changes done in composer.json:
Code analysis
in Doctrine 2.3, the clone method of a Proxy was simple
===> Cloning use the public property
ClassMetadataInfo->reflFieldsin order to process the copy of fieldsin Doctrine 2.4, the clone method delegate the process to a callback method which comes that we can see in ProxyFactory.createCloner method
====> Cloning use
ClassMetadataInfo->getReflectionClass()->getProperties()in order to process the copy of fieldsIn our use case,
ClassMetadataInfo->reflFieldswas containing all the fields of the entity and its superclass, private+protected, butClassMetadataInfo->getReflectionClass()->getProperties()returns only protected fields of the superclass.So it's only copying partially the entity.
Workaround
Declare all the fields of the
MappedSuperClassas protected, rather than private@Ocramius commented on GitHub (Apr 2, 2016):
Can you check if
ClassMetadataInfo#getReflectionProperties()can be used instead?@betd-claumond commented on GitHub (Apr 4, 2016):
Hello,
Thanks for the feedback.
Yes, it's working properly for my use case with the code
Regards,
Christophe
@Ocramius commented on GitHub (Sep 10, 2016):
Handled in #5768