python - Can you extend SQLAlchemy Query class and use different ones in the same session? -


i using sql alchemy orm , have classes/tables each of may have custom queries. let's say, want add table fruit filtering possibility called with_seed giving me fruits seeds, , table cutlery filtering method is_sharp giving me sharp cutlery. want define these filters extensions query object, , want use them in same transaction:

def delete_sharp_cutlery_and_seedy_fruits(session_factory):   session = session_factory()   session.query(fruit).with_seed().delete(synchronize_session='fetch')   session.query(cutlery).is_sharp().delete(synchronize_session='fetch')   session.commit() 

is possible?


this related question here. solution there requires different sessions created different query classes.

you can pass session query constructor

customquery(entities=[fruit], session=session).with_seed().delete(synchronize_session='fetch') 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -