diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-26 14:40:45 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-26 14:40:45 +0530 |
commit | 9d3d60c64a9ce69b9932f5c543112199e576c2ad (patch) | |
tree | 6cc2d5fbf8f707274683a93cda8ac32b175b7663 /activerecord | |
parent | 284d186cf4e055cefb2f8482d016e3bd09e9c341 (diff) | |
download | rails-9d3d60c64a9ce69b9932f5c543112199e576c2ad.tar.gz rails-9d3d60c64a9ce69b9932f5c543112199e576c2ad.tar.bz2 rails-9d3d60c64a9ce69b9932f5c543112199e576c2ad.zip |
Ensure preload and eager_load finder methods accept multiple arguments
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 14 |
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 |