Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.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_Flask Sqlalchemy - Fatal编程技术网

Python 烧瓶sqlalchemy使用单表过滤多柱

Python 烧瓶sqlalchemy使用单表过滤多柱,python,sqlalchemy,flask-sqlalchemy,Python,Sqlalchemy,Flask Sqlalchemy,我有一个表attender\u Handshake,其中有两列from\u id和to\u id,我想查询from_id和to_id的status列等于0的所有行,该列在另一个表Attendee_Login上引用,其中from_id和to_id是主键 与会者握手 from_id(外键) to_id(外键) 与会者登录 login\u id(主键) 状态 由于您需要对与会者登录名进行两次单独的引用,因此您需要一个别名: attendee_alias = db.aliased(Attendee

我有一个表
attender\u Handshake
,其中有两列
from\u id
to\u id
,我想查询
from_id
to_id
status
列等于0的所有行,该列在另一个表
Attendee_Login
上引用,其中
from_id
to_id
是主键

与会者握手

  • from_id(外键)
  • to_id(外键)
与会者登录

  • login\u id(主键)
  • 状态

由于您需要对与会者登录名进行两次单独的引用,因此您需要一个别名:

attendee_alias = db.aliased(Attendee_Login)
然后是一个简单的连接和过滤问题:

Attendee_Handshake.query.\
    join(Attendee_Login, Attendee_Login.login_id == Attendee_Handshake.from_id).\
    join(attendee_alias, attendee_alias.login_id == Attendee_Handshake.to_id).\
    filter(Attendee_Login.status == 0,
           attendee_alias.status == 0)