提交 261d2841 编写于 作者: E Ernie Miller

Add eq_any.

上级 d6816550
......@@ -11,6 +11,14 @@ def eq other
Nodes::Equality.new self, other
end
def eq_any others
first = Nodes::Equality.new self, others.shift
Nodes::Grouping.new others.inject(first) { |memo,expr|
Nodes::Or.new(memo, Nodes::Equality.new(self, expr))
}
end
def in other
case other
when Arel::SelectManager
......
......@@ -142,6 +142,22 @@ module Attributes
end
end
describe '#eq_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
relation[:id].eq_any([1,2]).should be_kind_of Nodes::Grouping
end
it 'should generate multiple ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq_any([1,2])
mgr.to_sql.should be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 OR "users"."id" = 2)
}
end
end
describe '#in' do
it 'can be constructed with a list' do
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册