aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/algebra/relations/operations/where.rb10
-rw-r--r--lib/arel/engines/memory/relations/operations.rb2
-rw-r--r--spec/algebra/unit/relations/where_spec.rb1
3 files changed, 7 insertions, 6 deletions
diff --git a/lib/arel/algebra/relations/operations/where.rb b/lib/arel/algebra/relations/operations/where.rb
index 6c9c5ed755..5c50fe8640 100644
--- a/lib/arel/algebra/relations/operations/where.rb
+++ b/lib/arel/algebra/relations/operations/where.rb
@@ -1,17 +1,17 @@
module Arel
class Where < Compound
- attributes :relation, :predicate
+ attributes :relation, :predicates
deriving :==
requires :restricting
def initialize(relation, *predicates, &block)
- predicate = block_given?? yield(relation) : predicates.shift
- @relation = predicates.empty?? relation : Where.new(relation, *predicates)
- @predicate = predicate.bind(@relation)
+ predicates = [yield(relation)] + predicates if block_given?
+ @predicates = predicates.map { |p| p.bind(relation) }
+ @relation = relation
end
def wheres
- @wheres ||= (relation.wheres + [predicate]).collect { |p| p.bind(self) }
+ @wheres ||= relation.wheres + predicates
end
end
end
diff --git a/lib/arel/engines/memory/relations/operations.rb b/lib/arel/engines/memory/relations/operations.rb
index 5d7b7670b6..55b4dcb677 100644
--- a/lib/arel/engines/memory/relations/operations.rb
+++ b/lib/arel/engines/memory/relations/operations.rb
@@ -1,7 +1,7 @@
module Arel
class Where < Compound
def eval
- unoperated_rows.select { |row| predicate.eval(row) }
+ unoperated_rows.select { |row| predicates.all? { |p| p.eval(row) } }
end
end
diff --git a/spec/algebra/unit/relations/where_spec.rb b/spec/algebra/unit/relations/where_spec.rb
index 96b95b5823..48a8dc5038 100644
--- a/spec/algebra/unit/relations/where_spec.rb
+++ b/spec/algebra/unit/relations/where_spec.rb
@@ -9,6 +9,7 @@ module Arel
describe '#initialize' do
it "manufactures nested where relations if multiple predicates are provided" do
+ pending "This is not true anymore"
another_predicate = @relation[:name].lt(2)
Where.new(@relation, @predicate, another_predicate). \
should == Where.new(Where.new(@relation, another_predicate), @predicate)