[BUG] Incorrect handling of ManyToMany relation with unique constraint #5355

Closed
opened 2026-01-22 15:05:21 +01:00 by admin · 2 comments
Owner

Originally created by @aivus on GitHub (Dec 21, 2016).

Originally assigned to: @Ocramius on GitHub.

It happens in case of using ManyToMany relation and using unique=true constraint.

collectionUpdates has updates, where add new relation item before remove old.
It causes error:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'UNIQ_C978869F4584665A'

cd1a5fcadc/lib/Doctrine/ORM/UnitOfWork.php (L388)

Workaround: change order of getting entities

See failing tests here:
https://github.com/doctrine/doctrine2/pull/6185

Originally created by @aivus on GitHub (Dec 21, 2016). Originally assigned to: @Ocramius on GitHub. It happens in case of using ManyToMany relation and using unique=true constraint. `collectionUpdates` has updates, where add new relation item before remove old. It causes error: ``` SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'UNIQ_C978869F4584665A' ``` https://github.com/doctrine/doctrine2/blob/cd1a5fcadce6cd5fe3ee17360503d73e82852339/lib/Doctrine/ORM/UnitOfWork.php#L388 Workaround: change order of getting entities See failing tests here: https://github.com/doctrine/doctrine2/pull/6185
admin added the BugInvalid labels 2026-01-22 15:05:21 +01:00
admin closed this issue 2026-01-22 15:05:21 +01:00
Author
Owner

@aivus commented on GitHub (Dec 21, 2016):

It could be fixed by adding different methods deleteRow and insertRow instead of update to CollectionPersister. But it affects interface and could be done only in the next version.

But I'm not sure about efficiency of this.

@aivus commented on GitHub (Dec 21, 2016): It could be fixed by adding different methods `deleteRow` and `insertRow` instead of `update` to `CollectionPersister`. But it affects interface and could be done only in the next version. But I'm not sure about efficiency of this.
Author
Owner

@Ocramius commented on GitHub (Dec 23, 2016):

Closing as invalid as per https://github.com/doctrine/doctrine2/pull/6185#issuecomment-268925556

@Ocramius commented on GitHub (Dec 23, 2016): Closing as `invalid` as per https://github.com/doctrine/doctrine2/pull/6185#issuecomment-268925556
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5355