CodeIgniter Forums
ALERT: Model soft deletes have changed the underlying data structure - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Development (https://forum.codeigniter.com/forumdisplay.php?fid=27)
+--- Thread: ALERT: Model soft deletes have changed the underlying data structure (/showthread.php?tid=73844)



ALERT: Model soft deletes have changed the underlying data structure - kilishan - 06-12-2019

A heads up for any developers working on a CI4 codebase. I just merged in a breaking change to the way soft deletes work. Instead of being a simple boolean flag called deleted, the default field has been changed to a new column called deleted_at. This should be either a DATETIME or INTEGER column that matches what that table is using for created_at and updated_at.

This not only brings it in line with the other timestamps across the Model and Entities, but provides a better chance for data forensics on the case something gets deleted so you can help your client figure out what might have caused things to go missing.

I have been thinking about this change for a while now, as I'm not really sure why I originally created it as a boolean. Probably an artifact from examining several MY_Model classes that were popular from previous versions of CI. If that change was ever going to happen, it had to happen prior to a Release Candidate.

I know this will likely cause some headaches for people that have already started projects on CI4 beta, but this is the last expected breaking change prior to a RC (which is close!).


RE: ALERT: Model soft deletes have changed the underlying data structure - InsiteFX - 06-12-2019

Thanks for the update Lonnie.


RE: ALERT: Model soft deletes have changed the underlying data structure - MGatner - 06-21-2019

Soft deleted rows can still be updated. This might not be particularly useful, but since `deleted_at` only affects the "find" methods (which can themselves be overridden using `withDeleted`) you could conceivably have an application that would have updates after soft deletion. Off the top of my head, I work with one app that "publishes" and "unpublishes" items regularly that would benefit greatly from such a distinction.


RE: ALERT: Model soft deletes have changed the underlying data structure - ignitedcms - 07-22-2019

I really like the idea of soft deletes, great work.