Thanks for your guided questions and the example pattern. Indeed the basic query would be
session.query(SomeObject).filter(SomeObject.loginname.like("example")).filter(SomeObject.company_id == SomeHTTPSessionGlobal.company_id)
As this query is extension is used many times in my codebase (due to the multi-tentancy nature of the concept) I want to automate this. I have implemented and new Query-class;
session = sessionmaker(bind=engine, query_cls=MyQuery)
In this MyQuery two things need to happen; A) check whether the queried table has the certain company_id field and B) automatically implement the additional filter to add the SomeHTTPSessionGlobal.company_id (which is based on the sub-domain)
=> Is by altering the get(), __ite__ and from_self() functions enough to effect all queries?
=> How to get the adjusted table and detect whether an company_id field exists?
In such that when the SomeObject has an field company_id, it automatically applies an additional filter. So that my query in the code may be;
session.query(SomeObject).filter(SomeObject.loginname.like("example"))
Thanks