Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change SQLAlchemy's Session.delete() behaviour

Are there any configuration possibilities concerning the delete()-method of SQLAlchemy's Sessions? I'd like to have the corresponding objects marked with a deleted flag in the database and not removed from it. Is there a way to achieve this? The aim is to build a database without destructive updates without losing the advantages of SQLAlchemy's cascading features.

like image 709
Fynn Avatar asked Oct 09 '22 23:10

Fynn


1 Answers

Create your own session class inheriting from Session and override the delete() method with your own logic (for those classes that require logical delete), falling back to the default implemetation for the other objects. If you use sessionmaker or similar factory, you can provide your class in the class_ parameter as well.

Hopefully, this answers your question. But, having said/written that, there is SOOO MUCH MORE to the logical deletion especially in term of Referential Integrity, that one can write a series of articles on that.

like image 59
van Avatar answered Oct 13 '22 11:10

van