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

Closed
ricohumme opened this Issue Jun 3, 2016 · 1 comment

Projects

None yet

2 participants

@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

@Ocramius Ocramius added the Bug label Jun 5, 2016
@Ocramius Ocramius added this to the 2.5.5 milestone Jun 5, 2016
@Ocramius Ocramius self-assigned this Jun 5, 2016
@Ocramius Ocramius added a commit that referenced this issue Jun 5, 2016
@Ocramius Ocramius #5849 #5850 correcting test scenario: identity map could not be built…
… with auto-generated identities+persist
34d8e00
@Ocramius Ocramius added a commit that referenced this issue Jun 5, 2016
@Ocramius Ocramius #5849 #5850 renamed `clearIdentityMap` to `clearIdentityMapForEntityN…
…ame`, for clarity
14e0800
@Ocramius Ocramius added a commit that referenced this issue Jun 5, 2016
@Ocramius Ocramius #5849 #5850 renamed `clearEntityInsertions` to `clearEntityInsertions…
…ForEntityName`, for clarity
b9b952c
@Ocramius Ocramius added a commit that referenced this issue Jun 5, 2016
@Ocramius Ocramius #5849 #5850 minor performance optimization - avoiding `get_class()` c…
…alls on all entity insertions
68c5d76
@Ocramius Ocramius added a commit that closed this issue Jun 5, 2016
@Ocramius Ocramius Merge branch 'fix/#5850-clearing-specific-entity-name-should-clear-al…
…so-its-entity-insertions'

Close #5850
Close #5849
3bc61d5
@Ocramius Ocramius closed this in 3bc61d5 Jun 5, 2016
@Ocramius Ocramius added a commit that referenced this issue Jun 5, 2016
@Ocramius Ocramius #5849 #5850 correcting test scenario: identity map could not be buil…
…t with auto-generated identities+persist
7378035
@Ocramius Ocramius added a commit that referenced this issue Jun 5, 2016
@Ocramius Ocramius #5849 #5850 renamed `clearIdentityMap` to `clearIdentityMapForEntityN…
…ame`, for clarity
ec4dd4a
@Ocramius Ocramius added a commit that referenced this issue Jun 5, 2016
@Ocramius Ocramius #5849 #5850 renamed `clearEntityInsertions` to `clearEntityInsertions…
…ForEntityName`, for clarity
fecadf0
@Ocramius Ocramius added a commit that referenced this issue Jun 5, 2016
@Ocramius Ocramius Merge branch 'fix/#5850-clearing-specific-entity-name-should-clear-al…
…so-its-entity-insertions-2.5' into 2.5

Close #5850
Close #5849
0af9ee0
@Ocramius
Member
Ocramius commented Jun 5, 2016

Handled in #5850

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment