Thanks to visit codestin.com
Credit goes to github.com

Skip to content

UnitOfWork->clear doesn't clear entityInsertions when entityName is passed #5849

@ricohumme

Description

@ricohumme

Hi,

I found that when I was clearing the EntityManager for a specific entity class, only detach is executed for entities within the identityMap.
Clearing the scheduled insertions for that class isn't done.
Did anyone else experience this?
What I found is that newly persisted entities are not added to the identityMap and therefor are not removed.

My solution to this issue would be the following:

// Class UnitOfWork
// Method clear
if ($entityName === null) {
    ...
} else {
    foreach ($this->identityMap as $className => $entities) {
        ...
    }

    foreach ($this->entityInsertions as $hash => $entity) {
        if (get_class($entity) != $entityName) {
            continue;
        }
        unset($this->entityInsertions[$hash]);
    }
}

This has been proven to work in my case.

Let me know what you think

For this I created a pull request

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions