Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python sqlalchemy是否在应用过滤器后更改查询对象?_Python_Sqlalchemy - Fatal编程技术网

Python sqlalchemy是否在应用过滤器后更改查询对象?

Python sqlalchemy是否在应用过滤器后更改查询对象?,python,sqlalchemy,Python,Sqlalchemy,假设我有一个查询对象 query = session.query(SomeModel) \ .filter(SomeModel.foo == 'bar') \ .filter(SomeModel.active == True) 您能否在执行查询之前修改对象列表,并维护所有相同的筛选器 i、 e 因此,生成的查询对象是: session.query(SomeModel.id, SomeModel.name) \ .filter(SomeModel.foo == 'bar'

假设我有一个查询对象

query = session.query(SomeModel) \
    .filter(SomeModel.foo == 'bar') \
    .filter(SomeModel.active == True)
您能否在执行查询之前修改对象列表,并维护所有相同的筛选器

i、 e

因此,生成的查询对象是:

session.query(SomeModel.id, SomeModel.name) \
    .filter(SomeModel.foo == 'bar') \
    .filter(SomeModel.active == True)

哇,已经找到答案了。如果有人搜索此项,将保持此项打开:

query = query.with_entities(SomeModel.id, SomeModel.name)
query = query.with_entities(SomeModel.id, SomeModel.name)