【发布时间】:2018-08-15 02:10:53
【问题描述】:
SQLAlchemy for MySQL 没有外键,我创建了这些表:
USER TABLE:
user_id
user_name
BLOCK TABLE:
user_id
blocked_user_id
POST TABLE:
post_id
post_user_id
post_content
COMMENT TABLE:
comment_id
comment_user_id
comment_content
post_id
post_user_id
我想选择帖子的 cmets 和 COMMENT.comment_user_id 不在 BLOCK.blocked_user_id 中,我试过这个,但结果为空:
comments = COMMENT.query.outerjoin(BLOCK, BLOCK.blocked_user_id == COMMENT.comment_user_id).filter(COMMENT.post_id == postid, COMMENT.post_user_id != current_user.user_id).all()
作为替代解决方案,我必须使用两个查询步骤,第一步选择所有被阻止的用户,第二步选择帖子的 cmets 过滤器
COMMENT.comment_user_id.notin_(blocked_users)
【问题讨论】:
标签: python mysql sqlalchemy flask-sqlalchemy