aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb9
-rw-r--r--activerecord/test/models/author.rb2
2 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 0ac56c6168..6f23a832ef 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -55,6 +55,15 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal preloaded, Marshal.load(Marshal.dump(preloaded))
end
+ def test_preload_with_nested_association
+ posts = Post.preload(:author, :author_favorites).to_a
+
+ assert_no_queries do
+ posts.each(&:author)
+ posts.each(&:author_favorites)
+ end
+ end
+
def test_preload_sti_rhs_class
developers = Developer.includes(:firms).all.to_a
assert_no_queries do
diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb
index 8b5a2fa0c8..3eb8a3a0fa 100644
--- a/activerecord/test/models/author.rb
+++ b/activerecord/test/models/author.rb
@@ -217,6 +217,8 @@ class AuthorAddress < ActiveRecord::Base
end
class AuthorFavorite < ActiveRecord::Base
+ default_scope { order(id: :asc) }
+
belongs_to :author
belongs_to :favorite_author, class_name: "Author"
end