aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-08-01 21:42:38 +0100
committerJon Leighton <j@jonathanleighton.com>2012-08-01 21:59:46 +0100
commit437851ea02983e7f039de1a09a69ee32f7681134 (patch)
treeec7e9b6941d39b515875f3dbd91232e004f15717 /activerecord/test/cases/relations_test.rb
parent4efebdedf8d8b8e2be711fafb560daddb15e48ad (diff)
downloadrails-437851ea02983e7f039de1a09a69ee32f7681134.tar.gz
rails-437851ea02983e7f039de1a09a69ee32f7681134.tar.bz2
rails-437851ea02983e7f039de1a09a69ee32f7681134.zip
Add `Relation#load`
This method explicitly loads the records and then returns `self`. Rather than deciding between "do I want an array or a relation?", most people are actually asking themselves "do I want to eager load or lazy load?" Therefore, this method provides a way to explicitly eager-load without having to switch from a `Relation` to an array. Example: @posts = Post.where(published: true).load
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 4aa1977cf9..1fbd76bc03 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1342,4 +1342,12 @@ class RelationTest < ActiveRecord::TestCase
node = relation.arel.constraints.first.grep(Arel::Attributes::Attribute).first
assert_equal table_alias, node.relation
end
+
+ test '#load' do
+ relation = Post.all
+ assert_queries(1) do
+ assert_equal relation, relation.load
+ end
+ assert_no_queries { relation.to_a }
+ end
end