I'm trying to understand the Active Record find_each method to retrieve records in batches.
If a Post has_many comments (thousands of comments) and I want to render each comment, I can do:
@post.comments.each { |comment| ... }
But is it faster if I do :
@post.comments.find_each { |comment| ... } ?
Is the second query valid?
The way I'm seeing this is that by doing @post.comments before the find_each is already getting all the comments for each post so ending the query with find_each is probably redundant ?!
This is the full block of code in a rails app views folder:
json.comments @post.comments.find_each do |comment|
json.rating comment.rating
json.content comment.content
end
Thank you