From 842f5c2dad8ed021274c16f2dc231c15ddefba18 Mon Sep 17 00:00:00 2001 From: Tomohito Ozaki Date: Fri, 6 Mar 2015 11:55:22 +0900 Subject: Read already loaded association records from association.target For performance, Avoid instantiate CollectionProxy. Fixes #12537 --- activerecord/test/cases/associations/eager_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 7d8b933992..2c6f199cf1 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1349,4 +1349,10 @@ class EagerAssociationTest < ActiveRecord::TestCase post = Post.eager_load(:tags).where('tags.name = ?', 'General').first assert_equal posts(:welcome), post end + + # CollectionProxy#reader is expensive, so the preloader avoids calling it. + test "preloading has_many_through association avoids calling association.reader" do + ActiveRecord::Associations::HasManyAssociation.any_instance.expects(:reader).never + Author.preload(:readonly_comments).first! + end end -- cgit v1.2.3