Checking boundable not only IN clause but also NOT IN clause

This commit is contained in:
Ryuta Kamizono 2018-11-03 14:45:25 +09:00
parent b858c2c76c
commit 19f0f14074
4 changed files with 24 additions and 8 deletions

@ -12,15 +12,11 @@ def accept(*)
def visit_Arel_Nodes_In(o, collector)
@preparable = false
super
end
if Array === o.right && !o.right.empty?
o.right.delete_if do |bind|
if Arel::Nodes::BindParam === bind && Relation::QueryAttribute === bind.value
!bind.value.boundable?
end
end
end
def visit_Arel_Nodes_NotIn(o, collector)
@preparable = false
super
end

@ -23,6 +23,10 @@ def eql?(other)
def nil?
value.nil?
end
def boundable?
!value.respond_to?(:boundable?) || value.boundable?
end
end
end
end

@ -579,6 +579,10 @@ def visit_Arel_Table(o, collector)
end
def visit_Arel_Nodes_In(o, collector)
if Array === o.right && !o.right.empty?
o.right.keep_if { |value| boundable?(value) }
end
if Array === o.right && o.right.empty?
collector << "1=0"
else
@ -589,6 +593,10 @@ def visit_Arel_Nodes_In(o, collector)
end
def visit_Arel_Nodes_NotIn(o, collector)
if Array === o.right && !o.right.empty?
o.right.keep_if { |value| boundable?(value) }
end
if Array === o.right && o.right.empty?
collector << "1=1"
else
@ -788,6 +796,10 @@ def inject_join(list, collector, join_str)
}
end
def boundable?(value)
!value.respond_to?(:boundable?) || value.boundable?
end
def has_join_sources?(o)
o.relation.is_a?(Nodes::JoinSource) && !o.relation.right.empty?
end

@ -36,8 +36,12 @@ def teardown
def test_too_many_binds
bind_params_length = @connection.send(:bind_params_length)
topics = Topic.where(id: (1 .. bind_params_length).to_a << 2**63)
assert_equal Topic.count, topics.count
topics = Topic.where.not(id: (1 .. bind_params_length).to_a << 2**63)
assert_equal 0, topics.count
end
def test_bind_from_join_in_subquery