通过 OR 或 AND (Arel, Rails3) 连接(粘合)where 条件 [英] Concatenate (glue) where conditions by OR or AND (Arel, Rails3)

查看:42
本文介绍了通过 OR 或 AND (Arel, Rails3) 连接(粘合)where 条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个复杂查询(使用子查询等...),并想用 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 种方法:首先返回第一个 where,第二个,第三个 - OR 连接.

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) 连接(粘合)where 条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆