title: In Rails, what's the difference between find_each and where?
body: <p>In Rails, both <a href="http://apidock.com/rails/v4.2.1/ActiveRecord/Batches/find_each">find_each</a> and <a href="http://apidock.com/rails/v4.2.1/ActiveRecord/QueryMethods/where">where</a> are used for retrieving data from Database supported by ActiveRecord.</p>
  
  <p>You can pass your query condition to <code>where</code>, like:</p>
  
  <pre><code>c = Category.where(:name =&gt; 'Ruby', :position =&gt; 1)
  </code></pre>
  
  <p>And you can pass batch size to <code>find_each</code>, like:</p>
  
  <pre><code>Hedgehog.find_each(batch_size: 50).map{ |p| p.to_json }
  </code></pre>
  
  <p>But what's the difference between the following 2 code?</p>
  
  <pre><code># code 1
  Person.where("age &gt; 21").find_each(batch_size: 50) do |person|
    # processing
  end
  
  # code 2
  Person.where("age &gt; 21").each do |person|
    # processing
  end
  </code></pre>
  
  <p>Does code 1 batch retrieve 50 tuples each time, and code 2 retrieve all tuples in one time? More details explaination is welcomed.</p>
  
  <p>My opinion is:</p>
  
  <ol>
  <li>both <code>where</code> and <code>find_each</code> can be used for batch retrieving, but user can define batch size when using <code>find_each</code>.</li>
  <li><code>find_each</code> does not support passing query condition.</li>
  </ol>
  
  <p>Please correct me if my understanding is wrong.</p>