diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2011-05-19 21:12:11 -0700 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2011-05-19 21:12:11 -0700 |
commit | 0cb812a50ebf5eaf0653efca721704dbb60ffc7d (patch) | |
tree | 842bb861f6e658b6f80d3638b4c7b05078dcd7ae /activerecord | |
parent | 0d310d590c310ed6551fb38164379a2465caaa89 (diff) | |
download | rails-0cb812a50ebf5eaf0653efca721704dbb60ffc7d.tar.gz rails-0cb812a50ebf5eaf0653efca721704dbb60ffc7d.tar.bz2 rails-0cb812a50ebf5eaf0653efca721704dbb60ffc7d.zip |
Changing examples: use 'each' instead of 'for in'
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 8 |
1 files changed, 4 insertions, 4 deletions
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 <tt>:author</tt> # 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 |