Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unscope when an eq node which has no arel attribute #38583

Merged
merged 1 commit into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion activerecord/lib/arel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/relations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down