Skip to content

Commit 4ed9797

Browse files
committed
remove deprecated support to preload instance-dependent associaitons.
Addresses ed56e59#commitcomment-9145960
1 parent a076256 commit 4ed9797

File tree

4 files changed

+16
-32
lines changed

4 files changed

+16
-32
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 preload instnace-dependent associations.
2+
3+
*Yves Senn*
4+
15
* Remove deprecated support for PostgreSQL ranges with exclusive lower bounds.
26

37
*Yves Senn*

activerecord/lib/active_record/reflection.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,10 @@ def check_preloadable!
343343
return unless scope
344344

345345
if scope.arity > 0
346-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
346+
raise ArgumentError, <<-MSG.squish
347347
The association scope '#{name}' is instance dependent (the scope
348-
block takes an argument). Preloading happens before the individual
349-
instances are created. This means that there is no instance being
350-
passed to the association scope. This will most likely result in
351-
broken or incorrect behavior. Joining, Preloading and eager loading
352-
of these associations is deprecated and will be removed in the future.
348+
block takes an argument). Preloading instance dependent scopes is
349+
not supported.
353350
MSG
354351
end
355352
end

activerecord/test/cases/associations/eager_test.rb

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -826,18 +826,6 @@ def test_limited_eager_with_numeric_in_association
826826
)
827827
end
828828

829-
def test_preload_with_interpolation
830-
assert_deprecated do
831-
post = Post.includes(:comments_with_interpolated_conditions).find(posts(:welcome).id)
832-
assert_equal [comments(:greetings)], post.comments_with_interpolated_conditions
833-
end
834-
835-
assert_deprecated do
836-
post = Post.joins(:comments_with_interpolated_conditions).find(posts(:welcome).id)
837-
assert_equal [comments(:greetings)], post.comments_with_interpolated_conditions
838-
end
839-
end
840-
841829
def test_polymorphic_type_condition
842830
post = Post.all.merge!(:includes => :taggings).find(posts(:thinking).id)
843831
assert post.taggings.include?(taggings(:thinking_general))
@@ -1294,23 +1282,22 @@ def test_deep_including_through_habtm
12941282
assert_equal pets(:parrot), Owner.including_last_pet.first.last_pet
12951283
end
12961284

1297-
test "include instance dependent associations is deprecated" do
1285+
test "preloading and eager loading of instance dependent associations is not supported" do
12981286
message = "association scope 'posts_with_signature' is"
1299-
assert_deprecated message do
1300-
begin
1301-
Author.includes(:posts_with_signature).to_a
1302-
rescue NoMethodError
1303-
# it's expected that preloading of this association fails
1304-
end
1287+
error = assert_raises(ArgumentError) do
1288+
Author.includes(:posts_with_signature).to_a
13051289
end
1290+
assert_match message, error.message
13061291

1307-
assert_deprecated message do
1308-
Author.preload(:posts_with_signature).to_a rescue NoMethodError
1292+
error = assert_raises(ArgumentError) do
1293+
Author.preload(:posts_with_signature).to_a
13091294
end
1295+
assert_match message, error.message
13101296

1311-
assert_deprecated message do
1297+
error = assert_raises(ArgumentError) do
13121298
Author.eager_load(:posts_with_signature).to_a
13131299
end
1300+
assert_match message, error.message
13141301
end
13151302

13161303
test "preloading readonly association" do

activerecord/test/models/post.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ def greeting
7272
through: :author_with_address,
7373
source: :author_address_extra
7474

75-
has_many :comments_with_interpolated_conditions,
76-
->(p) { where "#{"#{p.aliased_table_name}." rescue ""}body = ?", 'Thank you for the welcome' },
77-
:class_name => 'Comment'
78-
7975
has_one :very_special_comment
8076
has_one :very_special_comment_with_post, -> { includes(:post) }, :class_name => "VerySpecialComment"
8177
has_one :very_special_comment_with_post_with_joins, -> { joins(:post).order('posts.id') }, class_name: "VerySpecialComment"

0 commit comments

Comments
 (0)