Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add deprecation for the preload_associations method. Fixes #3022.

  • Loading branch information...
commit 6c5295f473d1914ee0bb0f6e7dc3acbf07c5099b 1 parent 7d603ff
@jonleighton jonleighton authored
View
12 activerecord/lib/active_record/associations.rb
@@ -5,6 +5,7 @@
require 'active_support/core_ext/string/conversions'
require 'active_support/core_ext/module/remove_method'
require 'active_support/core_ext/class/attribute'
+require 'active_support/deprecation'
module ActiveRecord
class InverseOfAssociationNotFoundError < ActiveRecordError #:nodoc:
@@ -1574,6 +1575,17 @@ def belongs_to(name, options = {})
def has_and_belongs_to_many(name, options = {}, &extension)
Builder::HasAndBelongsToMany.build(self, name, options, &extension)
end
+
+ protected
+
+ def preload_associations(records, associations, options = {}) #:nodoc:
+ ActiveSupport::Deprecation.warn(
+ "preload_associations(records, associations, options = {}) is deprecated. Use " \
+ "ActiveRecord::Associations::Preloader.new(records, associations, options = {}).run " \
+ "instead."
+ )
+ Preloader.new(records, associations, options).run
+ end
end
end
end
View
12 activerecord/test/cases/associations/eager_test.rb
@@ -1060,4 +1060,16 @@ def test_join_eager_with_nil_order_should_generate_valid_sql
Post.includes(:comments).order(nil).where(:comments => {:body => "Thank you for the welcome"}).first
end
end
+
+ def test_deprecated_preload_associations
+ post = Post.first
+
+ assert_deprecated do
+ Post.send(:preload_associations, [post], :comments)
+ end
+
+ assert_no_queries do
+ post.comments.to_a
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.