Soft delete (marked a record as deleted but not delete data)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
totza2010
User
Posts: 109

Soft delete (marked a record as deleted but not delete data)

Post by totza2010 »

How to setting soft delete all table?

When delete data in table, data is update column deleteAt to timestamp but not delete data, and not show data in list page.


arbei
User
Posts: 9384

Post by arbei »

I believe you can only customize the generated script to do that.


totza2010
User
Posts: 109

Post by totza2010 »

Yes, I'm testing customizations. But try asking in case there is anyone who has ever tried this. or can give additional advice.


mobhar
User
Posts: 11726

Post by mobhar »

You may replace return true; line in Row_Deleting server event by return false; and before that line, you may call ExecuteStatement() with your UPDATE SQL statement, and update the deleteAt field with CurrentDateTime().

In addition, if your database supports transaction, you need to commit the changes after calling ExecuteStatement():

Conn()->commit();


daveb
User
Posts: 32

Post by daveb »

I have used a different approach by adding an "Activated" field to each record in the tables. I do not generate delete options but use edit to turn on/off the activated "switch". All lookups for new data entry only selects active records, but reports show use active and inactive records. I then create a new view to allow the "real" delete and it is protected by the security functions so only the administrator level can access. I have also planned so additional checks before the delete is done - for example is the record linked to another by lookup or similar ?

Hope that is useful,

Dave


vintoICT
User
Posts: 407

Post by vintoICT »

Simple add a new column on the table . Name softdelete or any name u want . Make it Int . Set default value to 0 . On deletion update the table where id to 1 .

To hide soft deleted data on list page for example , filter on table setup where softdelete = 1


Post Reply