Skip to content

Commit e3b9779

Browse files
committed
Remove deprecated private API in ActiveRecord::Associations::Preloader
1 parent 0792661 commit e3b9779

File tree

2 files changed

+14
-36
lines changed

2 files changed

+14
-36
lines changed

activerecord/lib/active_record/associations/preloader.rb

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,21 @@ class Preloader # :nodoc:
9393
# associations before querying the database. This can save database
9494
# queries by reusing in-memory objects. The optimization is only applied
9595
# to single associations (i.e. :belongs_to, :has_one) with no scopes.
96-
def initialize(associate_by_default: true, **kwargs)
97-
if kwargs.empty?
98-
ActiveSupport::Deprecation.warn("Calling `Preloader#initialize` without arguments is deprecated and will be removed in Rails 7.0.")
99-
else
100-
@records = kwargs[:records]
101-
@associations = kwargs[:associations]
102-
@scope = kwargs[:scope]
103-
@available_records = kwargs[:available_records] || []
104-
@associate_by_default = associate_by_default
96+
def initialize(records:, associations:, scope: nil, available_records: [], associate_by_default: true)
97+
@records = records
98+
@associations = associations
99+
@scope = scope
100+
@available_records = available_records || []
101+
@associate_by_default = associate_by_default
105102

106-
@tree = Branch.new(
107-
parent: nil,
108-
association: nil,
109-
children: associations,
110-
associate_by_default: @associate_by_default,
111-
scope: @scope
112-
)
113-
@tree.preloaded_records = records
114-
end
103+
@tree = Branch.new(
104+
parent: nil,
105+
association: nil,
106+
children: @associations,
107+
associate_by_default: @associate_by_default,
108+
scope: @scope
109+
)
110+
@tree.preloaded_records = @records
115111
end
116112

117113
def empty?
@@ -124,12 +120,6 @@ def call
124120
loaders
125121
end
126122

127-
def preload(records, associations, preload_scope = nil)
128-
ActiveSupport::Deprecation.warn("`preload` is deprecated and will be removed in Rails 7.0. Call `Preloader.new(kwargs).call` instead.")
129-
130-
Preloader.new(records: records, associations: associations, scope: preload_scope).call
131-
end
132-
133123
def branches
134124
@tree.children
135125
end

activerecord/test/cases/associations_test.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,18 +397,6 @@ def test_preload_with_scope
397397
assert_equal [comments(:greetings)], post.comments
398398
end
399399

400-
def test_legacy_preload_with_scope
401-
post = posts(:welcome)
402-
403-
assert_deprecated do
404-
preloader = ActiveRecord::Associations::Preloader.new
405-
preloader.preload([post], :comments, Comment.where(body: "Thank you for the welcome"))
406-
end
407-
408-
assert_predicate post.comments, :loaded?
409-
assert_equal [comments(:greetings)], post.comments
410-
end
411-
412400
def test_preload_makes_correct_number_of_queries_on_array
413401
post = posts(:welcome)
414402

0 commit comments

Comments
 (0)