Much like other ORMs, ActiveRecord makes it almost effortless to accidentally do very stupid queries in bulk. For example (from
http://guides.rubyonrails.org/active_record_querying.html) this code
clients = Client.all(:limit => 10)
clients.each do |client|
puts client.address.postcode
end
looks harmless but requires eleven sequential round-trips to the database. This version
clients = Client.includes(:address).limit(10)
clients.each do |client|
puts client.address.postcode
end
still requires two, and one of the queries
gets bigger as the number of ids increases. You can get into find_by_sql, but at that point ActiveRecord isn't adding any value.