-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DDC-3372: PersistentCollection clear function takes snapshot when the collection is cleared #4173
Comments
Comment created by @Ocramius: Can you please abstract your problem into a test case? |
Comment created by wardpeet: if that helps yes. The problem is that i'm not sure it's a bug. It might be the way you guys wanted it to be. |
Comment created by @Ocramius: It looks like a bug to me: the snapshot should be taken only when no snapshot was there upfront, as far as I know. |
Comment created by deatheriam: I just got bitten by the same issue. I need to have access to all elements being cleared in a collection before it gets actually cleared, but because its internal collection gets cleared before PersistentCollection is able to take a snapshot, all these elements are lost. |
Comment created by deatheriam: @ward Peeters, have you ever created the test case in question? |
Comment created by wardpeet: No i haven't will make one today if you're not doing it. I made workaround for now. |
This comment was marked as spam.
This comment was marked as spam.
@githoober please don't bump: provide a failing test case instead. |
Test case for ManyToManyBasicAssociationTest.php: public function testManyToManyCollectionTraceClearedItems()
{
$user = $this->addCmsUserGblancoWithGroups($groupCount = 10);
$user->groups->clear();
$this->assertEquals(
$groupCount,
count($user->groups->getDeleteDiff()),
"There should be 10 groups in the snapshot of the collection"
);
} |
I just ran into this problem today. I have a relation that if it gets emptied the association shows no changes. I traced it down to this line within orm/lib/Doctrine/ORM/PersistentCollection.php Line 565 in 01187c9
Why do we take a snapshot when a collection is cleared? This doesn't make any sense to me. #2272 seems to be the exact same issue. |
Okay I see the problem. We want clear() to be fast so we mark the collection for deletion, clear it in memory, then take a new snapshot to prevent the collection from iterating the elements and trying to remove them one by one after it has already been cleared as well as avoiding calculating these changes at all. Basically we do this for performance reasons. Considering a snapshot is "A snapshot of the collection at the moment it was fetched from the database." (from the PHPDoc) I don't think we should be taking another snapshot during the I built an auditor that watches updates to various entities and logs what the changes are and who did them. For this reason I need the snapshot to be the collection the moment it was fetched otherwise when a relation gets emptied I get no log records. I would love it if we could find a better way of keeping Any ideas? |
Jira issue originally created by user wardpeet:
I'm not sure if it's a bug or you guys have a reason why you do it. The problem occurs when you do a
$coll->clear()
it will clear the collection and whenever it's cleared thetakeSnapshot
is ran as well so our snapshot is empty so we lose the previous state of the collection.The text was updated successfully, but these errors were encountered: