这就是我获得整数和@codes
对象的方式
@codes = user.codes.joins(:community).merge(Community.not_deleted).order("codes.updated_at DESC").limit(10)
@codes_count = user.codes.joins(:community).merge(Community.not_deleted).order("codes.updated_at DESC").count
有什么技术可以减少 sql 查询吗?
就像是
@codes_all = user.codes.joins(:community).merge(Community.not_deleted).order("codes.updated_at DESC")
@codes_count = @codes_all.count
@codes = @codes_all.limit(10)
是否有可能使这种急切的加载像这样?
@codes_all = user.codes.includes(community: [:country, :language]).joins(:community).merge(Community.not_deleted).order("codes.updated_at DESC")
@codes_count = @codes_all.count
@codes = @codes_all.limit(10)