mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Restrictions should be able to contain multiple predicates.
This commit is contained in:
parent
09765829d3
commit
8991daa5e3
3 changed files with 7 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue