未验证 提交 7205b9f4 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #38583 from kamipo/fix_unscope_with_arel_sql

Fix `unscope` when an `eq` node which has no arel attribute
......@@ -53,7 +53,7 @@ def self.fetch_attribute(value, &block) # :nodoc:
Arel::Nodes::GreaterThan, Arel::Nodes::GreaterThanOrEqual
if value.left.is_a?(Arel::Attributes::Attribute)
yield value.left
else
elsif value.right.is_a?(Arel::Attributes::Attribute)
yield value.right
end
when Arel::Nodes::Or
......
......@@ -2050,6 +2050,18 @@ def test_unscope_specific_where_value
assert_equal 1, posts.unscope(where: :body).count
end
def test_unscope_with_arel_sql
posts = Post.where(Arel.sql("'Welcome to the weblog'").eq(Post.arel_attribute(:title)))
assert_equal 1, posts.count
assert_equal Post.count, posts.unscope(where: :title).count
posts = Post.where(Arel.sql("posts.title").eq("Welcome to the weblog"))
assert_equal 1, posts.count
assert_equal 1, posts.unscope(where: :title).count
end
def test_unscope_grouped_where
posts = Post.where(
title: ["Welcome to the weblog", "So I was thinking", nil]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册