aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2015-01-05 11:44:14 +0100
committerYves Senn <yves.senn@gmail.com>2015-01-05 11:44:14 +0100
commit4ed97979d14c5e92eb212b1a629da0a214084078 (patch)
treeefcef0221da350471596a63318332361e67cbaf5 /activerecord
parenta076256d63f64d194b8f634890527a5ed2651115 (diff)
downloadrails-4ed97979d14c5e92eb212b1a629da0a214084078.tar.gz
rails-4ed97979d14c5e92eb212b1a629da0a214084078.tar.bz2
rails-4ed97979d14c5e92eb212b1a629da0a214084078.zip
remove deprecated support to preload instance-dependent associaitons.
Addresses https://github.com/rails/rails/commit/ed56e596a0467390011bc9d56d462539776adac1#commitcomment-9145960
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/reflection.rb9
-rw-r--r--activerecord/test/cases/associations/eager_test.rb31
-rw-r--r--activerecord/test/models/post.rb4
4 files changed, 16 insertions, 32 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index e54d06e935..57d9f10a01 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Remove deprecated support to preload instnace-dependent associations.
+
+ *Yves Senn*
+
* Remove deprecated support for PostgreSQL ranges with exclusive lower bounds.
*Yves Senn*
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 66f2b6b768..dab5a502a5 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -343,13 +343,10 @@ module ActiveRecord
return unless scope
if scope.arity > 0
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ raise ArgumentError, <<-MSG.squish
The association scope '#{name}' is instance dependent (the scope
- block takes an argument). Preloading happens before the individual
- instances are created. This means that there is no instance being
- passed to the association scope. This will most likely result in
- broken or incorrect behavior. Joining, Preloading and eager loading
- of these associations is deprecated and will be removed in the future.
+ block takes an argument). Preloading instance dependent scopes is
+ not supported.
MSG
end
end
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index fdb437d11d..371635d20a 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -826,18 +826,6 @@ class EagerAssociationTest < ActiveRecord::TestCase
)
end
- def test_preload_with_interpolation
- assert_deprecated do
- post = Post.includes(:comments_with_interpolated_conditions).find(posts(:welcome).id)
- assert_equal [comments(:greetings)], post.comments_with_interpolated_conditions
- end
-
- assert_deprecated do
- post = Post.joins(:comments_with_interpolated_conditions).find(posts(:welcome).id)
- assert_equal [comments(:greetings)], post.comments_with_interpolated_conditions
- end
- end
-
def test_polymorphic_type_condition
post = Post.all.merge!(:includes => :taggings).find(posts(:thinking).id)
assert post.taggings.include?(taggings(:thinking_general))
@@ -1294,23 +1282,22 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal pets(:parrot), Owner.including_last_pet.first.last_pet
end
- test "include instance dependent associations is deprecated" do
+ test "preloading and eager loading of instance dependent associations is not supported" do
message = "association scope 'posts_with_signature' is"
- assert_deprecated message do
- begin
- Author.includes(:posts_with_signature).to_a
- rescue NoMethodError
- # it's expected that preloading of this association fails
- end
+ error = assert_raises(ArgumentError) do
+ Author.includes(:posts_with_signature).to_a
end
+ assert_match message, error.message
- assert_deprecated message do
- Author.preload(:posts_with_signature).to_a rescue NoMethodError
+ error = assert_raises(ArgumentError) do
+ Author.preload(:posts_with_signature).to_a
end
+ assert_match message, error.message
- assert_deprecated message do
+ error = assert_raises(ArgumentError) do
Author.eager_load(:posts_with_signature).to_a
end
+ assert_match message, error.message
end
test "preloading readonly association" do
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 56073cc588..7b637c9e3f 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -72,10 +72,6 @@ class Post < ActiveRecord::Base
through: :author_with_address,
source: :author_address_extra
- has_many :comments_with_interpolated_conditions,
- ->(p) { where "#{"#{p.aliased_table_name}." rescue ""}body = ?", 'Thank you for the welcome' },
- :class_name => 'Comment'
-
has_one :very_special_comment
has_one :very_special_comment_with_post, -> { includes(:post) }, :class_name => "VerySpecialComment"
has_one :very_special_comment_with_post_with_joins, -> { joins(:post).order('posts.id') }, class_name: "VerySpecialComment"