SqlAlchemy: filter to match all instead of any values in list?

前端 未结 3 521
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 06:58

I want to query a junction table for the value of column aID that matches all values of a list of ids ids=[3,5] in column bID.

3条回答
  •  渐次进展
    2020-12-19 07:53

    Based on @Gordon Linoff answer and with two tables A and B where A has a relation one- to-many towards B called A.bs the SqlAlchemy equivalent would be:

    from sqlalchemy import func  
    session.query(A).join(B).filter(B.id.in_()).group_by(A.id).having(func.count(A.bs) == len()).all()
    

提交回复
热议问题