Delete / Inactive


When creating a large scale commercial application is it best to allow the user to delete records from the DB?


Make the record inactive which mimicks the delete? But the data still resides in the DB?


That depends on the records you wish to delete and how they affect other aspects of the application -ie history reports

For "sensitive" tables I always use fields deleted, deletedId and deleteTime…

have a default scope of deleted=0, deletedId is the ID of the user that deleted the record, deletedTime is the timestamp

To purge old deleted data a cron job can be used…

Thanks for your input everyone.

I know its a question of scenrios and preferences etc.

But …

Do you think it is worth storing deleted data?

Take a scenario where a company that uses your “accounting” program… .at the end of the year call you explaining that something is not right… that your program is not working good… that they should have there XXX amount of invoices… but there are 3 missing… that is your program that failed… (or any similar situation - can’t get a better example right now)

So what do you think in this situation… how worth is to have all the deleted invoices in the database… and with a simple select you can say… yes here are the 3 “missing” invoices… deleted by XX at that date and that time… ;)

Yeah I suppose your right.

you can add a column called it as : isDelete boolean default is false

and if user delete this record, and change false to true.

I think your database is not deleted it,but your users can not see it. :D

Yeah, does that require only selecting records where isDelete = false at the application level? Or does it do it automatically?

You might look into the defaultScope() function of the model (CActiveRecord). I use it ‘order’, and it can be overridden in an individual CDbCriteria (say in the actionAdmin() call.)