Soft-delete record by flagging a value (Flag for delete)
In our application, when the user deletes a row, we do not want to do a hard-delete, instead we only want to soft-delete the record by flagging a field. Is that possible to accomplish using the phpGrid?
Solution:
That's possible with trigger for delete. Update the row, then immediate abort the trigger to prevent delete from executing.
Example:
CREATE TRIGGER orders_soft_delete_trigger
BEFORE DELETE ON orders
FOR EACH ROW BEGIN
UPDATE orders SET cancel_flag = 1 WHERE
order_id = OLD.order_id;
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT
= 'DELETE canceled'; -- raise MySql generic error
manually
END;