forsqlalchemyindeterminatelongORcondition####需求分析需求是这样的,我现在有一个列表,列表中的数据是这样的```[(a,b),(c,d),(e,f)...]```数据库中有`from_user_id`和`to_user_id`两个字段,我现在需要实现一个类似于下面的查询```where(from_user_id=aandto_user_id=b)or(from_user_id=candto_user_id=d)or(from_user_id=eandto_user_id=f)...```####解决方案-####方法1```fromsqlalchemyimporttuple_fromsqlalchemyimportor_,and_#modelisUserProfile#itemsarethe上面的列表,limit对于列表长度UserProfile.query.filter(tuple_(UserProfile.from_user_id,UserProfile.to_user_id).in_(items)).limit(limit)all()```这个[(a,),(b,),(c,),(d,),(e,),(f,)],即如果只有一个字段作为过滤条件,也可以像这样写```#列表必须是TupleUserProfile.query.filter(tuple_(UserProfile.from_user_id).in_(items)).limit(limit).all()```例子如下ows:```In[5]:UserProfile.query.filter(tuple_(UserProfile.id).in_([(14,),(232,)])).all()Out[5]:[
