Soft Delete Pattern

138 views
Skip to first unread message

Andrew Martin

unread,
Jul 3, 2023, 11:13:55 PM7/3/23
to sqlalchemy
Hello,

I have a base class I tend to use that includes a Boolean is_deleted field so that pretty much every object has that available.

Is there a good pattern for setting a filter on these objects that automatically adds a WHERE is_deleted = 'false'?

Or does that just have to be added as a filter on every .query(...) statement?


Thanks,

andrew

Mike Bayer

unread,
Jul 4, 2023, 12:05:28 AM7/4/23
to noreply-spamdigest via sqlalchemy
this is a major area of functionality that begins with the "with_loader_criteria" feature: https://docs.sqlalchemy.org/en/20/orm/queryguide/api.html#sqlalchemy.orm.with_loader_criteria


--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.

Andrew Martin

unread,
Jul 4, 2023, 12:13:29 AM7/4/23
to sqlalchemy
This is awesome!

Thank you, Mike!

-andrew

Reply all
Reply to author
Forward
0 new messages