提交 abc19c37 编写于 作者: W Washington Luiz

Let `unscope` ignore non Arel scope.where_values

上级 d4d041c1
......@@ -883,8 +883,6 @@ def where_unscoping(target_value)
when Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual
subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right)
subrelation.name == target_value
else
raise "unscope(where: #{target_value.inspect}) failed: unscoping #{rel.class} \"#{rel}\" is unimplemented."
end
end
......
......@@ -149,6 +149,16 @@ def test_unscope_multiple_where_clauses
assert_equal expected, received
end
def test_unscope_string_where_clauses_involved
dev_relation = Developer.order('salary DESC').where("created_at > ?", 1.year.ago)
expected = dev_relation.collect { |dev| dev.name }
dev_ordered_relation = DeveloperOrderedBySalary.where(name: 'Jamis').where("created_at > ?", 1.year.ago)
received = dev_ordered_relation.unscope(where: [:name]).collect { |dev| dev.name }
assert_equal expected, received
end
def test_unscope_with_grouping_attributes
expected = Developer.order('salary DESC').collect { |dev| dev.name }
received = DeveloperOrderedBySalary.group(:name).unscope(:group).collect { |dev| dev.name }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册