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?