mirror of
https://github.com/doctrine/orm.git
synced 2026-04-24 06:58:19 +02:00
DDC-211: Exception is thrown after many calls to flush() #262
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Dec 15, 2009).
Jira issue originally created by user baumgartl:
Two classes having a many-to-many association:
Fill the database with some data:
After the user was added to the third group, an exception is thrown:
Using the EchoSqlLogger a strange SQL statement becomes visible (after the user was added to "group 3"):
Where does the delete statement come from? There is none of that in the code.
Interestingly the example works fine if the user is just added to three groups. If flush() is just called once at the end of the script, everything is fine too.
Many calls to flush() are expected to slow down execution time and/or increase memory consumption, but should work properly.
@doctrinebot commented on GitHub (Dec 15, 2009):
Comment created by nicokaiser:
The delete statement seems to come from \Doctrine\ORM\PersistentCollection#getDeleteDiff(), which returns the entities from the association that should be deleted (in this case this happens iff you delete associations between M:N entities):
This is done by an *array_udiff($this->_snapshot, $this->_coll->toArray(), array($this, '_compareRecords'))*, where _compareRecords is nothing more than $a === $b.
I modified getDeleteDiff() so it displays what it does and pasted the output here: http://pastie.org/744175
(the DIFF sections are only the DeleteDiffs). After successfully adding 3 Categories (303, 304, 305) Doctrine suddenly decides that the association Group[134]/Category[305] should be deleted, and then Group[134]/Category303 is re-inserted, which produces an exception of course.
The full log with SQL is here http://pastie.org/744183 (here the Group has id 138 instead of 134).
@doctrinebot commented on GitHub (Dec 15, 2009):
Comment created by romanb:
array_udiff is very weird. If anyone can explain me this behavior, I would be delighted:
The array_udiff behavior is the reason for this problem. I just dont understand it.
According to the manual: "Returns an array containing all the values of array1 ($snapshot in this case) that are not present in any of the other arguments. "
@doctrinebot commented on GitHub (Dec 15, 2009):
Comment created by romanb:
This should now be fixed. We're using array_udiff_assoc instead which behaves as expected and is faster. Also, this is a necessary preparation for DDC-213. This can now lead to join-table elements being deleted and reinserted when they change position in the collection, however this is expected and indeed needed for DDC-213. I don't see this as an issue for "unordered" collections.
@doctrinebot commented on GitHub (Dec 15, 2009):
Issue was closed with resolution "Fixed"