Skip to content

Commit 09cac8c

Browse files
committed
Remove deprecated force reload argument in association readers
1 parent 00e3973 commit 09cac8c

File tree

9 files changed

+12
-67
lines changed

9 files changed

+12
-67
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 force reload argument in singular and collection association readers.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated `activerecord.errors.messages.restrict_dependent_destroy.one` and
26
`activerecord.errors.messages.restrict_dependent_destroy.many` i18n scopes.
37

activerecord/lib/active_record/associations/collection_association.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,8 @@ module Associations
2525
# +load_target+ and the +loaded+ flag are your friends.
2626
class CollectionAssociation < Association #:nodoc:
2727
# Implements the reader method, e.g. foo.items for Foo.has_many :items
28-
def reader(force_reload = false)
29-
if force_reload
30-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
31-
Passing an argument to force an association to reload is now
32-
deprecated and will be removed in Rails 5.1. Please call `reload`
33-
on the result collection proxy instead.
34-
MSG
35-
36-
klass.uncached { reload }
37-
elsif stale_target?
28+
def reader
29+
if stale_target?
3830
reload
3931
end
4032

activerecord/lib/active_record/associations/singular_association.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@ module ActiveRecord
22
module Associations
33
class SingularAssociation < Association #:nodoc:
44
# Implements the reader method, e.g. foo.bar for Foo.has_one :bar
5-
def reader(force_reload = false)
6-
if force_reload && klass
7-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
8-
Passing an argument to force an association to reload is now
9-
deprecated and will be removed in Rails 5.1. Please call `reload`
10-
on the parent object instead.
11-
MSG
12-
13-
klass.uncached { reload }
14-
elsif !loaded? || stale_target?
5+
def reader
6+
if !loaded? || stale_target?
157
reload
168
end
179

activerecord/test/cases/associations/belongs_to_associations_test.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,12 +1131,6 @@ def test_reflect_the_most_recent_change
11311131
Column.create! record: record
11321132
assert_equal 1, Column.count
11331133
end
1134-
1135-
def test_association_force_reload_with_only_true_is_deprecated
1136-
client = Client.find(3)
1137-
1138-
assert_deprecated { client.firm(true) }
1139-
end
11401134
end
11411135

11421136
class BelongsToWithForeignKeyTest < ActiveRecord::TestCase

activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -955,12 +955,6 @@ def test_with_constant_class_name
955955
end
956956
end
957957

958-
def test_association_force_reload_with_only_true_is_deprecated
959-
developer = Developer.find(1)
960-
961-
assert_deprecated { developer.projects(true) }
962-
end
963-
964958
def test_alternate_database
965959
professor = Professor.create(name: "Plum")
966960
course = Course.create(name: "Forensics")

activerecord/test/cases/associations/has_many_associations_test.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,12 +2462,6 @@ def self.name
24622462
end
24632463
end
24642464

2465-
def test_association_force_reload_with_only_true_is_deprecated
2466-
company = Company.find(1)
2467-
2468-
assert_deprecated { company.clients_of_firm(true) }
2469-
end
2470-
24712465
class AuthorWithErrorDestroyingAssociation < ActiveRecord::Base
24722466
self.table_name = "authors"
24732467
has_many :posts_with_error_destroying,

activerecord/test/cases/associations/has_many_through_associations_test.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,12 +1204,6 @@ def test_has_many_through_with_scope_that_should_not_be_fully_merged
12041204
assert_nil Club.new.special_favourites.distinct_value
12051205
end
12061206

1207-
def test_association_force_reload_with_only_true_is_deprecated
1208-
post = Post.find(1)
1209-
1210-
assert_deprecated { post.people(true) }
1211-
end
1212-
12131207
def test_has_many_through_do_not_cache_association_reader_if_the_though_method_has_default_scopes
12141208
member = Member.create!
12151209
club = Club.create!

activerecord/test/cases/associations/has_one_associations_test.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,6 @@ def test_with_polymorphic_has_one_with_custom_columns_name
645645
end
646646
end
647647

648-
def test_association_force_reload_with_only_true_is_deprecated
649-
firm = Firm.find(1)
650-
651-
assert_deprecated { firm.account(true) }
652-
end
653-
654648
class SpecialBook < ActiveRecord::Base
655649
self.table_name = "books"
656650
belongs_to :author, class_name: "SpecialAuthor"

activerecord/test/cases/associations_test.rb

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ def test_force_reload
8888
assert firm.clients.empty?, "New firm should have cached no client objects"
8989
assert_equal 0, firm.clients.size, "New firm should have cached 0 clients count"
9090

91-
ActiveSupport::Deprecation.silence do
92-
assert !firm.clients(true).empty?, "New firm should have reloaded client objects"
93-
assert_equal 1, firm.clients(true).size, "New firm should have reloaded clients count"
94-
end
91+
firm.clients.reload
92+
93+
assert !firm.clients.empty?, "New firm should have reloaded client objects"
94+
assert_equal 1, firm.clients.size, "New firm should have reloaded clients count"
9595
end
9696

9797
def test_using_limitable_reflections_helper
@@ -104,19 +104,6 @@ def test_using_limitable_reflections_helper
104104
assert !using_limitable_reflections.call(mixed_reflections), "No collection associations (has many style) should pass"
105105
end
106106

107-
def test_force_reload_is_uncached
108-
firm = Firm.create!("name" => "A New Firm, Inc")
109-
Client.create!("name" => "TheClient.com", :firm => firm)
110-
111-
ActiveSupport::Deprecation.silence do
112-
ActiveRecord::Base.cache do
113-
firm.clients.each {}
114-
assert_queries(0) { assert_not_nil firm.clients.each {} }
115-
assert_queries(1) { assert_not_nil firm.clients(true).each {} }
116-
end
117-
end
118-
end
119-
120107
def test_association_with_references
121108
firm = companies(:first_firm)
122109
assert_includes firm.association_with_references.references_values, "foo"

0 commit comments

Comments
 (0)