I have a Many-to-Many table, in which I input some form info. I recently made this form dynamic, so that when an input elements value is changed, it is sent to database via AJAX.
So my question is:
Is it faster to try and find the values that exist, edit them, create the ones that don’t and delete the ones that are not used anymore OR Should I delete all of the values for the id, and insert all of the new ones?
In response to comment, an elaboration.
- A form , that has about 10 fields. Some of them mandatory, some not. Every time you access it, it generates a random identifier.
- When a user starts filling the form, after the focus an element is lost, the whole form is submitted through AJAX, and all of the values that are not empty, are input in the many to many table.
- The table has 3 fields : form identificator , element name , element value;
The question rephrased:
Do I delete all of the entries with the required form identificator, or try to find the fields and edit them?
It will require less code to delete all the existing relations and add new ones
Less code == fewer bugs, less developer time. So that is definitely faster.