Skip to content

Commit c313d91

Browse files
committed
Remove deprecated support to pass rewhere to ActiveRecord::Relation#merge
1 parent c09956a commit c313d91

File tree

6 files changed

+14
-142
lines changed

6 files changed

+14
-142
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated support to pass `rewhere` to `ActiveRecord::Relation#merge`.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated support to pass `deferrable: true` to `add_foreign_key`.
26

37
*Rafael Mendonça França*

activerecord/lib/active_record/relation/merger.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ class Relation
77
class HashMerger # :nodoc:
88
attr_reader :relation, :hash
99

10-
def initialize(relation, hash, rewhere = nil)
10+
def initialize(relation, hash)
1111
hash.assert_valid_keys(*Relation::VALUE_METHODS)
1212

1313
@relation = relation
1414
@hash = hash
15-
@rewhere = rewhere
1615
end
1716

1817
def merge
19-
Merger.new(relation, other, @rewhere).merge
18+
Merger.new(relation, other).merge
2019
end
2120

2221
# Applying values to a relation has some side effects. E.g.
@@ -44,11 +43,10 @@ def other
4443
class Merger # :nodoc:
4544
attr_reader :relation, :values, :other
4645

47-
def initialize(relation, other, rewhere = nil)
46+
def initialize(relation, other)
4847
@relation = relation
4948
@values = other.values
5049
@other = other
51-
@rewhere = rewhere
5250
end
5351

5452
NORMAL_VALUES = Relation::VALUE_METHODS - Relation::CLAUSE_METHODS -
@@ -178,7 +176,7 @@ def merge_single_values
178176
def merge_clauses
179177
relation.from_clause = other.from_clause if replace_from_clause?
180178

181-
where_clause = relation.where_clause.merge(other.where_clause, @rewhere)
179+
where_clause = relation.where_clause.merge(other.where_clause)
182180
relation.where_clause = where_clause unless where_clause.empty?
183181

184182
having_clause = relation.having_clause.merge(other.having_clause)

activerecord/lib/active_record/relation/spawn_methods.rb

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,10 @@ def merge(other, *rest)
4141
end
4242

4343
def merge!(other, *rest) # :nodoc:
44-
options = rest.extract_options!
45-
46-
if options.key?(:rewhere)
47-
if options[:rewhere]
48-
ActiveRecord.deprecator.warn(<<-MSG.squish)
49-
Specifying `Relation#merge(rewhere: true)` is deprecated, as that has now been
50-
the default since Rails 7.0. Setting the rewhere option will error in Rails 7.2
51-
MSG
52-
else
53-
ActiveRecord.deprecator.warn(<<-MSG.squish)
54-
`Relation#merge(rewhere: false)` is deprecated without replacement,
55-
and will be removed in Rails 7.2
56-
MSG
57-
end
58-
end
59-
6044
if other.is_a?(Hash)
61-
Relation::HashMerger.new(self, other, options[:rewhere]).merge
45+
Relation::HashMerger.new(self, other).merge
6246
elsif other.is_a?(Relation)
63-
Relation::Merger.new(self, other, options[:rewhere]).merge
47+
Relation::Merger.new(self, other).merge
6448
elsif other.respond_to?(:to_proc)
6549
instance_exec(&other)
6650
else

activerecord/lib/active_record/relation/where_clause.rb

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ def |(other)
2323
WhereClause.new(predicates | other.predicates)
2424
end
2525

26-
def merge(other, rewhere = nil)
27-
predicates = if rewhere
28-
except_predicates(other.extract_attributes)
29-
else
30-
predicates_unreferenced_by(other)
31-
end
26+
def merge(other)
27+
predicates = except_predicates(other.extract_attributes)
3228

3329
WhereClause.new(predicates | other.predicates)
3430
end
@@ -156,18 +152,6 @@ def equalities(predicates, equality_only)
156152
equalities
157153
end
158154

159-
def predicates_unreferenced_by(other)
160-
referenced_columns = other.referenced_columns
161-
162-
predicates.reject do |node|
163-
attr = extract_attribute(node) || begin
164-
node.left if equality_node?(node) && node.left.is_a?(Arel::Predications)
165-
end
166-
167-
attr && referenced_columns[attr]
168-
end
169-
end
170-
171155
def equality_node?(node)
172156
!node.is_a?(String) && node.equality?
173157
end

activerecord/test/cases/relation/merging_test.rb

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,23 @@ def test_merge_in_clause
2424

2525
assert_equal [mary], david_and_mary.merge(Author.where(id: mary))
2626
assert_equal [mary], david_and_mary.merge(Author.rewhere(id: mary))
27-
assert_deprecated(ActiveRecord.deprecator) do
28-
assert_equal [mary], david_and_mary.merge(Author.where(id: mary), rewhere: true)
29-
end
3027

3128
assert_equal [bob], david_and_mary.merge(Author.where(id: bob))
3229
assert_equal [bob], david_and_mary.merge(Author.rewhere(id: bob))
33-
assert_deprecated(ActiveRecord.deprecator) do
34-
assert_equal [bob], david_and_mary.merge(Author.where(id: bob), rewhere: true)
35-
end
3630

3731
assert_equal [david, bob], mary_and_bob.merge(Author.where(id: [david, bob]))
38-
assert_deprecated(ActiveRecord.deprecator) do
39-
assert_equal [david, bob], mary_and_bob.merge(Author.where(id: [david, bob]), rewhere: true)
40-
end
4132

4233
assert_equal [mary, bob], david_and_mary.merge(mary_and_bob)
43-
assert_deprecated(ActiveRecord.deprecator) do
44-
assert_equal [mary, bob], david_and_mary.merge(mary_and_bob, rewhere: true)
45-
end
4634
assert_equal [mary], david_and_mary.and(mary_and_bob)
4735
assert_equal authors, david_and_mary.or(mary_and_bob)
4836

4937
assert_equal [david, mary], mary_and_bob.merge(david_and_mary)
50-
assert_deprecated(ActiveRecord.deprecator) do
51-
assert_equal [david, mary], mary_and_bob.merge(david_and_mary, rewhere: true)
52-
end
5338
assert_equal [mary], david_and_mary.and(mary_and_bob)
5439
assert_equal authors, david_and_mary.or(mary_and_bob)
5540

5641
david_and_bob = Author.where(id: david).or(Author.where(name: "Bob"))
5742

5843
assert_equal [david], david_and_mary.merge(david_and_bob)
59-
assert_deprecated(ActiveRecord.deprecator) do
60-
assert_equal [david], david_and_mary.merge(david_and_bob, rewhere: true)
61-
end
6244
assert_equal [david], david_and_mary.and(david_and_bob)
6345
assert_equal authors, david_and_mary.or(david_and_bob)
6446
end
@@ -74,41 +56,23 @@ def test_merge_between_clause
7456

7557
assert_equal [mary], david_and_mary.merge(Author.where(id: mary))
7658
assert_equal [mary], david_and_mary.merge(Author.rewhere(id: mary))
77-
assert_deprecated(ActiveRecord.deprecator) do
78-
assert_equal [mary], david_and_mary.merge(Author.where(id: mary), rewhere: true)
79-
end
8059

8160
assert_equal [bob], david_and_mary.merge(Author.where(id: bob))
8261
assert_equal [bob], david_and_mary.merge(Author.rewhere(id: bob))
83-
assert_deprecated(ActiveRecord.deprecator) do
84-
assert_equal [bob], david_and_mary.merge(Author.where(id: bob), rewhere: true)
85-
end
8662

8763
assert_equal [david, bob], mary_and_bob.merge(Author.where(id: [david, bob]))
88-
assert_deprecated(ActiveRecord.deprecator) do
89-
assert_equal [david, bob], mary_and_bob.merge(Author.where(id: [david, bob]), rewhere: true)
90-
end
9164

9265
assert_equal [mary, bob], david_and_mary.merge(mary_and_bob)
93-
assert_deprecated(ActiveRecord.deprecator) do
94-
assert_equal [mary, bob], david_and_mary.merge(mary_and_bob, rewhere: true)
95-
end
9666
assert_equal [mary], david_and_mary.and(mary_and_bob)
9767
assert_equal authors, david_and_mary.or(mary_and_bob)
9868

9969
assert_equal [david, mary], mary_and_bob.merge(david_and_mary)
100-
assert_deprecated(ActiveRecord.deprecator) do
101-
assert_equal [david, mary], mary_and_bob.merge(david_and_mary, rewhere: true)
102-
end
10370
assert_equal [mary], david_and_mary.and(mary_and_bob)
10471
assert_equal authors, david_and_mary.or(mary_and_bob)
10572

10673
david_and_bob = Author.where(id: david).or(Author.where(name: "Bob"))
10774

10875
assert_equal [david], david_and_mary.merge(david_and_bob)
109-
assert_deprecated(ActiveRecord.deprecator) do
110-
assert_equal [david], david_and_mary.merge(david_and_bob, rewhere: true)
111-
end
11276
assert_equal [david], david_and_mary.and(david_and_bob)
11377
assert_equal authors, david_and_mary.or(david_and_bob)
11478
end
@@ -124,42 +88,24 @@ def test_merge_or_clause
12488

12589
assert_equal [mary], david_and_mary.merge(Author.where(id: mary))
12690
assert_equal [mary], david_and_mary.merge(Author.rewhere(id: mary))
127-
assert_deprecated(ActiveRecord.deprecator) do
128-
assert_equal [mary], david_and_mary.merge(Author.where(id: mary), rewhere: true)
129-
end
13091

13192
assert_equal [bob], david_and_mary.merge(Author.where(id: bob))
13293
assert_equal [bob], david_and_mary.merge(Author.rewhere(id: bob))
133-
assert_deprecated(ActiveRecord.deprecator) do
134-
assert_equal [bob], david_and_mary.merge(Author.where(id: bob), rewhere: true)
135-
end
13694

13795
assert_equal [david, bob], mary_and_bob.merge(Author.where(id: [david, bob]))
138-
assert_deprecated(ActiveRecord.deprecator) do
139-
assert_equal [david, bob], mary_and_bob.merge(Author.where(id: [david, bob]), rewhere: true)
140-
end
14196

14297

14398
assert_equal [mary, bob], david_and_mary.merge(mary_and_bob)
144-
assert_deprecated(ActiveRecord.deprecator) do
145-
assert_equal [mary, bob], david_and_mary.merge(mary_and_bob, rewhere: true)
146-
end
14799
assert_equal [mary], david_and_mary.and(mary_and_bob)
148100
assert_equal authors, david_and_mary.or(mary_and_bob)
149101

150102
assert_equal [david, mary], mary_and_bob.merge(david_and_mary)
151-
assert_deprecated(ActiveRecord.deprecator) do
152-
assert_equal [david, mary], mary_and_bob.merge(david_and_mary, rewhere: true)
153-
end
154103
assert_equal [mary], david_and_mary.and(mary_and_bob)
155104
assert_equal authors, david_and_mary.or(mary_and_bob)
156105

157106
david_and_bob = Author.where(id: david).or(Author.where(name: "Bob"))
158107

159108
assert_equal [david], david_and_mary.merge(david_and_bob)
160-
assert_deprecated(ActiveRecord.deprecator) do
161-
assert_equal [david], david_and_mary.merge(david_and_bob, rewhere: true)
162-
end
163109
assert_equal [david], david_and_mary.and(david_and_bob)
164110
assert_equal authors, david_and_mary.or(david_and_bob)
165111
end
@@ -172,14 +118,8 @@ def test_merge_not_in_clause
172118
assert_equal [david], non_mary_and_bob
173119

174120
assert_equal [david], Author.where(id: david).merge(non_mary_and_bob)
175-
assert_deprecated(ActiveRecord.deprecator) do
176-
assert_equal [david], Author.where(id: david).merge(non_mary_and_bob, rewhere: true)
177-
end
178121

179122
assert_equal [david], Author.where(id: mary).merge(non_mary_and_bob)
180-
assert_deprecated(ActiveRecord.deprecator) do
181-
assert_equal [david], Author.where(id: mary).merge(non_mary_and_bob, rewhere: true)
182-
end
183123
end
184124

185125
def test_merge_not_range_clause
@@ -190,14 +130,8 @@ def test_merge_not_range_clause
190130
assert_equal [david, mary], less_than_bob
191131

192132
assert_equal [david, mary], Author.where(id: david).merge(less_than_bob)
193-
assert_deprecated(ActiveRecord.deprecator) do
194-
assert_equal [david, mary], Author.where(id: david).merge(less_than_bob, rewhere: true)
195-
end
196133

197134
assert_equal [david, mary], Author.where(id: mary).merge(less_than_bob)
198-
assert_deprecated(ActiveRecord.deprecator) do
199-
assert_equal [david, mary], Author.where(id: mary).merge(less_than_bob, rewhere: true)
200-
end
201135
end
202136

203137
def test_merge_doesnt_duplicate_same_clauses
@@ -226,12 +160,6 @@ def test_merge_doesnt_duplicate_same_clauses
226160
assert_queries_match(/WHERE \(#{Regexp.escape(author_id)} IN \(1\)\)\z/) do
227161
assert_equal [david], only_david.merge(only_david)
228162
end
229-
230-
assert_queries_match(/WHERE \(#{Regexp.escape(author_id)} IN \(1\)\)\z/) do
231-
assert_deprecated(ActiveRecord.deprecator) do
232-
assert_equal [david], only_david.merge(only_david, rewhere: true)
233-
end
234-
end
235163
end
236164
end
237165

@@ -255,11 +183,6 @@ def test_relation_merging_with_arel_equalities_keeps_last_equality
255183
devs = Developer.where(salary_attr.eq(80000)).merge(Developer.where(salary_attr.eq(9000)))
256184
assert_equal [developers(:poor_jamis)], devs.to_a
257185

258-
assert_deprecated(ActiveRecord.deprecator) do
259-
devs = Developer.where(salary_attr.eq(80000)).merge(Developer.where(salary_attr.eq(9000)), rewhere: true)
260-
end
261-
assert_equal [developers(:poor_jamis)], devs.to_a
262-
263186
devs = Developer.where(salary_attr.eq(80000)).rewhere(salary_attr.eq(9000))
264187
assert_equal [developers(:poor_jamis)], devs.to_a
265188
end
@@ -271,11 +194,6 @@ def test_relation_merging_with_arel_equalities_keeps_last_equality_with_non_attr
271194
devs = Developer.where(abs_salary.eq(80000)).merge(Developer.where(abs_salary.eq(9000)))
272195
assert_equal [developers(:poor_jamis)], devs.to_a
273196

274-
assert_deprecated(ActiveRecord.deprecator) do
275-
devs = Developer.where(abs_salary.eq(80000)).merge(Developer.where(abs_salary.eq(9000)), rewhere: true)
276-
end
277-
assert_equal [developers(:poor_jamis)], devs.to_a
278-
279197
devs = Developer.where(abs_salary.eq(80000)).rewhere(abs_salary.eq(9000))
280198
assert_equal [developers(:poor_jamis)], devs.to_a
281199
end
@@ -399,24 +317,6 @@ def test_merging_duplicated_annotations
399317
Post.annotate("bar").merge(Post.annotate("foo")).merge(posts).to_a
400318
end
401319
end
402-
403-
def test_rewhere_true_is_deprecated
404-
message = <<-MSG.squish
405-
Specifying `Relation#merge(rewhere: true)` is deprecated
406-
MSG
407-
assert_deprecated(message, ActiveRecord.deprecator) do
408-
Author.where(id: 1).merge(Author.where(id: 2), rewhere: true)
409-
end
410-
end
411-
412-
def test_rewhere_false_is_deprecated
413-
message = <<-MSG.squish
414-
Relation#merge(rewhere: false)` is deprecated without replacement
415-
MSG
416-
assert_deprecated(message, ActiveRecord.deprecator) do
417-
Author.where(id: 1).merge(Author.where(id: 2), rewhere: false)
418-
end
419-
end
420320
end
421321

422322
class MergingDifferentRelationsTest < ActiveRecord::TestCase

guides/source/7_2_release_notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ Please refer to the [Changelog][active-record] for detailed changes.
162162

163163
* Remove deprecated support to pass `deferrable: true` to `add_foreign_key`.
164164

165+
* Remove deprecated support to pass `rewhere` to `ActiveRecord::Relation#merge`.
166+
165167
### Deprecations
166168

167169
* Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`

0 commit comments

Comments
 (0)