mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-1359: Deleting and inserting with unique index #1706
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 (Sep 2, 2011).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user rrafal@gmail.com:
I'm getting a database error when deleting and inserting records in a single unit of work. Consider this example:
I have a user and user_info tables. user_info stores additional data about a user as a list of key-values.
user: id, name, email, password
user_info: id, user_id, info_key, info_value
I created a unique index on user_info table: CREATE UNIQUE INDEX
user_info_keyONuser_info(user_id,key) ;Each table is represented as an Entity class.
Now, I run this code:
This causes MySQL error: "Integrity constraint violation: 1062 Duplicate entry". Doctrine ORM first persists new entities and then deletes old entities. I think the relevant code is at Doctrine/ORM/UnitOfWork :277-313. Everything works fine if I add flush() before line 2. Also, everything works fine if I change the index to non-unique.
@doctrinebot commented on GitHub (Jul 8, 2012):
Comment created by @ocramius:
I just got back to the UnitOfWork and (in latest master) it executes deletes as last operation (maybe to avoid cascades), and this is also documented.
In my opinion, you should do the operation of computing the changeset on your
infocollection manually...@doctrinebot commented on GitHub (Feb 9, 2013):
Issue was closed with resolution "Invalid"
@doctrinebot commented on GitHub (Feb 9, 2013):
Comment created by @ocramius:
Invalid usage of collection API/object graph