aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation.rb4
-rw-r--r--activerecord/test/cases/relations_test.rb14
2 files changed, 12 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 3dedf44190..c02acba786 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -11,11 +11,11 @@ module ActiveRecord
@eager_load_associations = eager_load
end
- def preload(associations)
+ def preload(*associations)
create_new_relation(@relation, @readonly, @associations_to_preload + Array.wrap(associations))
end
- def eager_load(associations)
+ def eager_load(*associations)
create_new_relation(@relation, @readonly, @associations_to_preload, @eager_load_associations + Array.wrap(associations))
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 50bd221bb3..d0a28c58e0 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -116,22 +116,28 @@ class RelationTest < ActiveRecord::TestCase
def test_find_with_included_associations
assert_queries(2) do
posts = Post.preload(:comments)
- posts.first.comments.first
+ assert posts.first.comments.first
end
assert_queries(2) do
posts = Post.preload(:comments).to_a
- posts.first.comments.first
+ assert posts.first.comments.first
end
assert_queries(2) do
posts = Post.preload(:author)
- posts.first.author
+ assert posts.first.author
end
assert_queries(2) do
posts = Post.preload(:author).to_a
- posts.first.author
+ assert posts.first.author
+ end
+
+ assert_queries(3) do
+ posts = Post.preload(:author, :comments).to_a
+ assert posts.first.author
+ assert posts.first.comments.first
end
end