Optimise the sql query to remove N+1 problem in Ruby on Rails and Mysql
There are 2 models Buyer and BuyerOrder with 1 to many relationship. class Buyer < ApplicationRecord has_many buyer_orders end class BuyerOrder < ApplicationRecord belongs_to buyer end I need to fetch total buyer_orders count and buyer name with group by buyer_id.…