Amin
Amin

Reputation: 2043

Auto deleting an object based on some conditions in sqlalchemy

Is there anyway to delete an object based on some conditions? For example, if cascade:delete-orphan is indicated in a relationship, it will delete the child when the parent is deleted. What I am looking for is to delete an object when some condition is satisfied.

Upvotes: 0

Views: 298

Answers (1)

zzzeek
zzzeek

Reputation: 75207

perhaps you're looking for query.delete() ?

session.query(MyClass).filter_by(some_col='fred').delete(synchronize_session=False)

Upvotes: 2

Related Questions