I have a Case object that can have many Floors (OneToMany), each Floor has a FloorType type that indicates its type. I also have a UniqueConstraint on my Floors object that will not allow two Floors of the same FloorType type for each case.
To embed Floors in each Case, I created a Symfony collection type for Floors and using js. I am adding new Floors to my Case.
The symfony doc for form collections says that if an item is not submitted, it will be automatically deleted from the database.
Now the problem is that if I have "Flooring for business" already in the database, when I delete the "Gender" in my form and add it again, it will be considered as a new INSERT, but since Doctrine does flash, doing INSERT first and DELETEs, I would get the error below for breaking a unique installed container:
SQLSTATE [23000]: Violation of integrity constraint: 1062 Duplicate entry "4-2" for the keyword "floor_case_floor_type_unique"
The value is that Doctrine is trying to insert a row into the Floors table with the same FloorType as the deleted one before trying to delete the last from the same table.
Is there a way to make the DELETE doctrine before INSERT or any other way to solve this problem?