Changing SQLAlchemy Session.delete () Behavior

Are there any configuration options related to the delete()SQLAlchemy method Sessions? I would like to have relevant objects marked with a remote flag in the database and not removed from it. Is there any way to achieve this? The goal is to create a database without disruptive updates without losing the benefits of cascading SQLAlchemy functions.

+5
source share
2 answers

Create your own session class that inherits from Sessionand override the method delete()using your own logic (for those classes for which it is required logical delete), returning to the default job for other objects. If you use sessionmaker or a similar factory, you can specify your class in the parameter class_.

Hope this answers your question. But, having said / written that there is SOOO MUCH MORE for logical deletion, especially in terms Referential Integrity, you can write a number of articles on this subject.

+4
source

The following article provides a good solution for soft removal.

0
source

All Articles