Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add eq_any.

  • Loading branch information...
commit 261d284136567edfeb4dbfd9403ebd95e6bdae75 1 parent d681655
@ernie ernie authored
View
8 lib/arel/attributes/attribute.rb
@@ -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
View
16 spec/attributes/attribute_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.