Multiple line updates result in a unique "Integrity constraint violation",

I have a unique restriction on the SKU column in the options table. I have a form where I can edit several options with corresponding SKUs. The classic problem ( question and question ) is this (and affects MySQL):

Suppose you have two lines with values:

  • SKU1
  • SKU2

If you exchange two values ​​in an edited collection, the unique test will succeed and the doctrine will release two updates.

The first will set SKU1 to SKU2 and will immediately fail with a unique restriction, because there are duplicate values ​​of SKU2 and SKU2.

  • SKU1 β†’ SKU2 (unique constaint error)
  • SKU2

What is the best way to solve it in Symfony 2.3 Form and Doctrine 2.4?

+4
source share
1 answer

Create a third value:

  • SKU1 β†’ _SKU1
  • SKU2 β†’ SKU1
  • _SKU1 β†’ SKU2
0
source

Source: https://habr.com/ru/post/1501830/


All Articles