Skip to content

Commit ec9e64d

Browse files
committed
Fix query building for where with tuple syntax and large values list
1 parent fd975a8 commit ec9e64d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

activerecord/lib/active_record/relation/predicate_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def grouping_queries(queries)
147147
queries.first
148148
else
149149
queries.map! { |query| query.reduce(&:and) }
150-
queries = queries.reduce { |result, query| Arel::Nodes::Or.new([result, query]) }
150+
queries = Arel::Nodes::Or.new(queries)
151151
Arel::Nodes::Grouping.new(queries)
152152
end
153153
end

activerecord/test/cases/relation/where_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ def test_where_with_tuple_syntax_and_regular_syntax_combined
139139
assert_equal [book_two], Cpk::Book.where(title: "The Alchemist", [:author_id, :id] => [[3, 4]])
140140
end
141141

142+
def test_with_tuple_syntax_and_large_values_list
143+
# sqlite3 raises "Expression tree is too large (maximum depth 1000)"
144+
skip if current_adapter?(:SQLite3Adapter)
145+
146+
assert_nothing_raised do
147+
ids = [[1, 2]] * 1500
148+
Cpk::Book.where([:author_id, :id] => ids).to_sql
149+
end
150+
end
151+
142152
def test_belongs_to_shallow_where
143153
author = Author.new
144154
author.id = 1

0 commit comments

Comments
 (0)