Reputation: 3794
I have a query that require to use the "or" |
operator :
Mymodel.query.filter((Mymodel.a== 'b') | (Mymodel.b == 'c'))
That works fine. However, I want my conditions to be put in an array of unkown length :
conds = [ Mymodel.a== 'b', Mymodel.b == 'c', Mymodel.c == 'd']
Mymodel.query.filter(???(conds))
Thanks !
Upvotes: 11
Views: 9113
Reputation: 1986
You are looking for or_
conds = [ Mymodel.a== 'b', Mymodel.b == 'c', Mymodel.c == 'd']
If you have the above list of conditions just pass them all to or_
from sqlalchemy import or_
Mymodel.query.filter(or_(*conds))
Upvotes: 20