如何在Rails 5 ActiveRecord中执行or
查询?另外,在ActiveRecord查询中是否可以将or
与where
链接起来?
如何在Rails 5 ActiveRecord中执行or
查询?另外,在ActiveRecord查询中是否可以将or
与where
链接起来?
在ActiveRecord
查询中链接or
子句和where
子句的能力将在Rails 5中可用.看related discussion and the pull request.
因此,你将能够在Rails 5分钟内完成以下工作:
用id
1或2获得post
分:
Post.where('id = 1').or(Post.where('id = 2'))
其他一些例子:
(A && B) || C:
Post.where(a).where(b).or(Post.where(c))
(A || B) && C:
Post.where(a).or(Post.where(b)).where(c)