From 0cb812a50ebf5eaf0653efca721704dbb60ffc7d Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 19 May 2011 21:12:11 -0700 Subject: Changing examples: use 'each' instead of 'for in' --- activerecord/lib/active_record/associations.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 3e8255d759..d1752a25ff 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -665,7 +665,7 @@ module ActiveRecord # # Consider the following loop using the class above: # - # for post in Post.all + # Post.all.each do |post| # puts "Post: " + post.title # puts "Written by: " + post.author.name # puts "Last comment on: " + post.comments.first.created_on @@ -674,7 +674,7 @@ module ActiveRecord # To iterate over these one hundred posts, we'll generate 201 database queries. Let's # first just optimize it for retrieving the author: # - # for post in Post.find(:all, :include => :author) + # Post.find(:all, :include => :author).each do |post| # # This references the name of the +belongs_to+ association that also used the :author # symbol. After loading the posts, find will collect the +author_id+ from each one and load @@ -683,7 +683,7 @@ module ActiveRecord # # We can improve upon the situation further by referencing both associations in the finder with: # - # for post in Post.find(:all, :include => [ :author, :comments ]) + # Post.find(:all, :include => [ :author, :comments ]).each do |post| # # This will load all comments with a single query. This reduces the total number of queries # to 3. More generally the number of queries will be 1 plus the number of associations @@ -691,7 +691,7 @@ module ActiveRecord # # To include a deep hierarchy of associations, use a hash: # - # for post in Post.find(:all, :include => [ :author, { :comments => { :author => :gravatar } } ]) + # Post.find(:all, :include => [ :author, { :comments => { :author => :gravatar } } ]).each do |post| # # That'll grab not only all the comments but all their authors and gravatar pictures. # You can mix and match symbols, arrays and hashes in any combination to describe the -- cgit v1.2.3