counter_cache has_many_through sql optimisation, reduce number of sql queries
问题 How I can optimise my SQL queries, to ignore situations like this: Meeting.find(5).users.size => SELECT COUNT(*) FROM ... WHERE ... User.find(123).meetings.size => SELECT COUNT(*) FROm ... WHERE ... I have no idea how to use counter_cache here. Here is my model relation: class Meeting < ActiveRecord::Base has_many :meeting_users has_many :users, :through => meeting_users end class User < ActiveRecord::Base has_many :meeting_users has_many :meetings, :through => meeting_users end class Meeting