For this method to work, you must use the second of them:
$metadata = $em->getClassMetadata('\CS\AcmeBundle\Entity\MyEntity'); $metadata = $em->getClassMetadata('CS\AcmeBundle\Entity\MyEntity');
The problem is that Doctrine will return the same class metadata values ββfor both. They both correctly identify the class file, read its annotations, etc. Obviously, they are equivalent, except that this is an absolute namespace and the other is not.
But these strings will return different instances from getClassMetadata . Changes in one will not be reflected in the other. If you want your intended method to work, you should use the second form, because this is what UnitOfWork uses. He uses this normalization:
// \Doctrine\ORM\UnitOfWork->getCommitOrder() ... $className = $this->em->getClassMetadata(get_class($entity))->name; $class = $this->em->getClassMetadata($className); ...
Note that in a related question, the solution uses get_class($entity) . This is probably enough to get the right behavior.
In even more detail: after repeatedly entering the code, I noticed that \Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory memoizing both versions of the class name string in its private property $loadedMetadata . The version that was used to actually erase the objects was the one that does not have a leading slash, and I edited it with a slash.
Since both rows return the same data, I think this is an implementation error.
Seth Battin Jul 21 '14 at 3:37 a.m. 2014-07-21 03:37
source share