Skip to content
Browse files

Add docs for eager_laod and preload

  • Loading branch information...
1 parent ee20be7 commit 91c8d91536b1f41f0c4518e67b4bf31b1ef4f109 @oscardelben oscardelben committed Jul 7, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 activerecord/lib/active_record/relation/query_methods.rb
View
10 activerecord/lib/active_record/relation/query_methods.rb
@@ -63,6 +63,12 @@ def includes!(*args)
self
end
+ # Forces eager loading by performing a LEFT OUTER JOIN on +args+:
+ #
+ # User.eager_load(:posts)
+ # => SELECT "users"."id" AS t0_r0, "users"."name" AS t0_r1, ...
+ # FROM "users" LEFT OUTER JOIN "posts" ON "posts"."user_id" =
+ # "users"."id"
def eager_load(*args)
args.blank? ? self : spawn.eager_load!(*args)
end
@@ -72,6 +78,10 @@ def eager_load!(*args)
self
end
+ # Allows preloading of +args+, in the same way that +includes+ does:
+ #
+ # User.preload(:posts)
+ # => SELECT "posts".* FROM "posts" WHERE "posts"."user_id" IN (1, 2, 3)
def preload(*args)
args.blank? ? self : spawn.preload!(*args)
end

0 comments on commit 91c8d91

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