Closed
Description
It is possible to call EntityManager::clear($entity)
or EntityRepository::clear()
to only clear one kind of entity from the identity map. this is done by calling detach on the entity instead of actually clearing the identity map and other related UnitOfWork
data.
Because clearing is not semantically the same as detaching an entity, it is not possible to do this anymore.
Alternative: If you need to detach many entities, you can perform this operation directly using the UnitOfWork. Potentially hide this away in a service or repository:
$unitOfWork = $entityManager->getUnitOfWork();
$entities = $unitOfWork->getIdentityMap()[Entity::class] ?? [];
foreach ($entities as $entity) {
$entityManager->detach($entity);
}