通过 OR 或 AND 连接(胶水)条件(Arel,Rails3) [英] Concatenate (glue) where conditions by OR or AND (Arel, Rails3)
本文介绍了通过 OR 或 AND 连接(胶水)条件(Arel,Rails3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个复杂查询(使用子查询等...)并且想用 OR 或 AND 语句将它们粘合在一起.
I have several complex queries (using subqueries, etc...) and want to glue them together with OR or AND statement.
例如:
where1=table.where(...)
where2=table.where(...)
我想要类似的东西
where3=where1.or where2
下一个例子对我不起作用:
Next example doesn't work for me:
users.where(users[:name].eq('bob').or(users[:age].lt(25)))
因为我有几个 where(..) 查询,我想连接 它们.
because of I have several where(..) queries and I want to concatenate them.
换句话说
我有 3 种方法:首先返回第一个位置,第二个第二个,第三个 - 或连接.
I have 3 methods: first return first where, second-second, third - OR concatenation.
我必须能够在我的应用程序中使用所有 3 种方法并保存 DRY 代码
I must have able to use all 3 methods in my application and save DRY code
推荐答案
你在找表格吗:
users.where(users[:name].eq('bob').or(users[:age].lt(25)))
文档:https://github.com/rails/arel
这篇关于通过 OR 或 AND 连接(胶水)条件(Arel,Rails3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文