我可以为一个查询指定query_cls
吗?我尝试使用query.session._query_cls
,当然,它不起作用......
我想要执行类似的操作:
query = Session.query(MyModel)...
default_querycls_result = query.all()
custom_querycls_result = query.update_query_cls(CustomQueryCls).all()
答案 0 :(得分:0)
您可以创建新的查询对象并复制__dict__
from sqlalchemy.orm.query import Query
class CustomQuery(Query):
pass
query = Session.query(MyModel)
default_querycls_result = query.all()
custom_query = CustomQuery(entities=[])
custom_query.__dict__ = query.__dict__.copy()
custom_querycls_result = custom_query.all()