The problem is that when you tell the doctrine to delete an object, it is removed from the identification card ( here ):
<?php public function scheduleForDelete($entity) { $oid = spl_object_hash($entity); // .... $this->removeFromIdentityMap($entity); // ... if ( ! isset($this->entityDeletions[$oid])) { $this->entityDeletions[$oid] = $entity; $this->entityStates[$oid] = self::STATE_REMOVED; } }
And when you do $entity->getAnswer()->getVotes()
, it does the following:
- Download all votes from the database
- For each vote, check if it is in the identification card, use the old
- If this is not an identity card, create a new object.
Try calling $entity->getAnswer()->getVotes()
before deleting the object. If the problem goes away, then I'm right. Of course, I would not offer this hack as a solution, just to make sure that we understand what is happening under the hood.
UPD, instead of $entity->getAnswer()->getVotes()
you should probably do foreach for all votes, due to lazy loading. If you simply call $entity->getAnswer()->getVotes()
, Doctrine will probably not do anything, and only load them when you start iterating over them.
source share