未验证 提交 673dbaba 编写于 作者: A Aaron Patterson 提交者: GitHub

Merge pull request #39288 from Edouard-chin/ec-homogeousin-where-values

Fix `AR::Relation#where_values_hash` with `HomogeousIn`:
......@@ -119,10 +119,9 @@ def equalities(predicates)
equalities = []
predicates.each do |node|
case node
when Arel::Nodes::Equality
if equality_node?(node)
equalities << node
when Arel::Nodes::And
elsif node.is_a?(Arel::Nodes::And)
equalities.concat equalities(node.children)
end
end
......
......@@ -32,6 +32,10 @@ def left
attribute
end
def right
attribute.quoted_array(values)
end
def table_name
attribute.relation.table_alias || attribute.relation.name
end
......
......@@ -214,6 +214,10 @@ def overlaps(other)
Arel::Nodes::Overlaps.new(self, other)
end
def quoted_array(others)
others.map { |v| quoted_node(v) }
end
private
def grouping_any(method_id, others, *extras)
nodes = others.map { |expr| send(method_id, expr, *extras) }
......@@ -231,10 +235,6 @@ def quoted_node(other)
Nodes.build_quoted(other, self)
end
def quoted_array(others)
others.map { |v| quoted_node(v) }
end
def infinity?(value)
value.respond_to?(:infinite?) && value.infinite?
end
......
......@@ -52,6 +52,13 @@ def test_empty_where_values_hash
assert_equal({}, relation.where_values_hash)
end
def test_where_values_hash_with_in_clause
relation = Relation.new(Post)
relation.where!(title: ["foo", "bar", "hello"])
assert_equal({ "title" => ["foo", "bar", "hello"] }, relation.where_values_hash)
end
def test_has_values
relation = Relation.new(Post)
relation.where!(id: 10)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册