CodeIgniter Forums
Query Builder Soft Deletes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Query Builder Soft Deletes (/showthread.php?tid=79303)



Query Builder Soft Deletes - PwrSrg - 05-26-2021

It would be extremely helpful if Soft Deletes were ALSO supported in Query Builder, and not exclusively to Model/BaseModel.

The current "method" of always having to remember to include where('deleted_at IS NULL') feels like a hack/workaround, like Builder is unfinished.

Thanks!  And thank you for all of the hard work! ??


RE: Query Builder Soft Deletes - seunex - 05-26-2021

CI developer team should please think about this feature.


RE: Query Builder Soft Deletes - MGatner - 05-28-2021

This isn't the first time this has come up. I understand the interest, but this is really bleeding together very different aspects of two components. Query Builder is our database abstraction layer: it lets use write object-oriented methods and have them interact with the database. Most importantly, it is completely structure agnostic - it knows nothing about what is in the database it interacts with. Models (ideally) are the inverse: they provide a concept of data structure without having to know how to interact with the database itself. In practice the Model does some SQL-fu, but that's out of necessity.
Convenience aside, it is a really bad idea (in my opinion) to make Query Builder aware/reliant on any particular data structure in the database. In order to "support soft deletes" Query Builder not only needs to know which tables are "entities", but it also needs to know which fields indicate deletion (like deleted_at) and what type of field that is (nullable, some time representation). At this point what you're doing is taking what makes Model a valuable class and muddying it into Builder.


RE: Query Builder Soft Deletes - includebeer - 05-29-2021

I agree with MGatner. It doesn't belong in the query builder. The builder is exactly that, a class to build generic SQL queries. It knows nothing about the business logic of your app and what column do what. Especially in the case where the "deleted_at" column has a different name. Also it would be even more confusing if I do a select(*) and it doesn't return everything because it decided to exclude the soft deleted rows.