4

I have a unique constraint on SKU column in a variant table. I have a form where I can edit multiple variants with respective SKUs. The classic problem (question and question) is as follows (and affects MySQL):

Suppose you have two rows with values:

  • SKU1
  • SKU2

If you swap two values in an edited collection, unique validation will succeed and doctrine will issue two updates.

The first one will set SKU1 to SKU2 and will immediately fail unique constraint because there are duplicate values SKU2 and SKU2.

  • SKU1 -> SKU2 (unique constaint fail)
  • SKU2

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

Community
  • 1
  • 1
TautrimasPajarskas
  • 2,686
  • 1
  • 32
  • 40

1 Answers1

0

Create a third value:

  • SKU1 --> _SKU1
  • SKU2 --> SKU1
  • _SKU1 --> SKU2
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Yes, this is one of the possible solutions. The other one is to begin transaction, lock table, disable unique constraint, update, enable, unlock, commit. But maybe there is even cleaner solution? – TautrimasPajarskas Sep 12 '13 at 12:02