I have an input in my DB that is soft deleted and if the user tries to create a new input with same name he will get a validation error "name already exists"
What is the best practice to solve this?
Is it better to leave it so because maybe the soft deleted entry will be restored which would cause a conflict (if i would somehow make it work so that the user can insert a new entry with the same name)
I don't know what is the right thing to do, but I'm sure that I'm not the only one who had this situation.
Your use case should ideally govern your entire architecture.
If you want your column (say name) to be unique, you would add a unique index to the column in your table structure and you would also add a validation to check for duplicates in your controller.
In my opinion, if you have a soft deletion and your use case requires your column to be unique, then you must add the validation (otherwise there would be a violation on inserts in your DB)
You don't have a choice
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With