Skip to content

Deprecate EntityManager::clear with argument of one entity class and EntityRepository::clear  #8460

Closed
@beberlei

Description

@beberlei

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);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions