How to preload counts in a list with ActiveRecord
28-Apr-2022 1267
Imagine that you need to put the number of likes for each post in a list, but avoiding n 1 queries.posts.each do |post| post.likes.count .
How to preload counts in a list with ActiveRecord #ruby #rubydeveloper #rubyonrails #preload #counts #ActiveRecord #activerecord https://rubyonrails.ba/link/how-to-preload-counts-in-a-list-with-activerecord