From 9d3d60c64a9ce69b9932f5c543112199e576c2ad Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 26 Dec 2009 14:40:45 +0530 Subject: Ensure preload and eager_load finder methods accept multiple arguments --- activerecord/lib/active_record/relation.rb | 4 ++-- activerecord/test/cases/relations_test.rb | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'activerecord') 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 -- cgit v1.2.3