Skip to content
Browse files

Ensure preload and eager_load finder methods accept multiple arguments

  • Loading branch information...
1 parent 284d186 commit 9d3d60c64a9ce69b9932f5c543112199e576c2ad @lifo lifo committed Dec 26, 2009
Showing with 12 additions and 6 deletions.
  1. +2 −2 activerecord/lib/active_record/relation.rb
  2. +10 −4 activerecord/test/cases/relations_test.rb
View
4 activerecord/lib/active_record/relation.rb
@@ -11,11 +11,11 @@ def initialize(klass, relation, readonly = false, preload = [], eager_load = [])
@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
View
14 activerecord/test/cases/relations_test.rb
@@ -116,22 +116,28 @@ def test_eager_association_loading_of_stis_with_multiple_references
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

0 comments on commit 9d3d60c

Please sign in to comment.
Something went wrong with that request. Please try again.