Answer the question
In order to leave comments, you need to log in
What is the best way to implement deletion of records?
yii2, there is a user record in the user table and storage records in the storage table.
to it (via actioUpdate), by selecting checkboxes, I bind warehouses by creating records with user_id and storage_id in the adjacent many-to-many table.
the next time a user record is edited via js, checkboxes with the required storage_id are marked, which are associated with the user_id.
when deselecting the checkbox and then saving the record, it is necessary to delete the deactivated record in the adjacent table.
Now it's done like this: every time I save a record, I delete all records with such storage_id that were not passed in the action.
but this, IMHO, is not correct.
question: how can this be done better and more correctly? in terms of performance. Simply pull this table every time, IMHO, is not very optimal.
Answer the question
In order to leave comments, you need to log in
it is better not to delete, but to mark as deleted in order to avoid errors with the integrity of the database
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question