提交 4baa9c45 编写于 作者: R Rafael Mendonça França

Merge pull request #17881 from deeeki/unscope_arel_where

Allow to unscope where conditions by arel_table with symbol
......@@ -909,7 +909,7 @@ def where_unscoping(target_value)
case rel
when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThanOrEqual
subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right)
subrelation.name == target_value
subrelation.name.to_s == target_value
end
end
......
......@@ -143,6 +143,14 @@ def test_unscope_with_where_attributes
expected_5 = Developer.order('salary DESC').collect(&:name)
received_5 = DeveloperOrderedBySalary.where.not("name" => ["Jamis", "David"]).unscope(where: :name).collect(&:name)
assert_equal expected_5, received_5
expected_6 = Developer.order('salary DESC').collect(&:name)
received_6 = DeveloperOrderedBySalary.where(Developer.arel_table['name'].eq('David')).unscope(where: :name).collect(&:name)
assert_equal expected_6, received_6
expected_7 = Developer.order('salary DESC').collect(&:name)
received_7 = DeveloperOrderedBySalary.where(Developer.arel_table[:name].eq('David')).unscope(where: :name).collect(&:name)
assert_equal expected_7, received_7
end
def test_unscope_multiple_where_clauses
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册