R
R
Ruslan Ruslanov2019-01-24 14:16:02
Yii
Ruslan Ruslanov, 2019-01-24 14:16:02

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

2 answer(s)
I
index0h, 2019-01-24
@dasauser

it is better not to delete, but to mark as deleted in order to avoid errors with the integrity of the database

M
morricone85, 2019-01-24
@morricone85

everything is fine, nothing needs to be changed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question