diff --git a/app/controllers/admins/schools_controller.rb b/app/controllers/admins/schools_controller.rb index 7e1626d98..8c4f1d59e 100644 --- a/app/controllers/admins/schools_controller.rb +++ b/app/controllers/admins/schools_controller.rb @@ -5,7 +5,7 @@ class Admins::SchoolsController < Admins::BaseController schools = Admins::SchoolQuery.call(params) - @schools = paginate schools.includes(:user_extensions) + @schools = paginate schools school_ids = @schools.map(&:id) @department_count = Department.where(school_id: school_ids).group(:school_id).count diff --git a/app/queries/admins/school_query.rb b/app/queries/admins/school_query.rb index 888cded97..3206f0858 100644 --- a/app/queries/admins/school_query.rb +++ b/app/queries/admins/school_query.rb @@ -17,6 +17,7 @@ class Admins::SchoolQuery < ApplicationQuery if keyword schools = schools.where('schools.name LIKE ?', "%#{keyword}%") end + schools = schools.left_joins(:user_extensions).select('schools.*, IFNULL(count(user_extensions.user_id),0) users_count').group('schools.id') custom_sort schools, params[:sort_by], params[:sort_direction] end end \ No newline at end of file diff --git a/app/views/admins/schools/shared/_list.html.erb b/app/views/admins/schools/shared/_list.html.erb index ff0b17992..dd0a054e3 100644 --- a/app/views/admins/schools/shared/_list.html.erb +++ b/app/views/admins/schools/shared/_list.html.erb @@ -33,7 +33,7 @@ <%= school.province %> <%= school.city %> <%= school.address %> - <%= school.user_extensions.count %> + <%= school.users_count %> <%= @department_count.fetch(school.id, 0) %> <%= school.created_at&.strftime('%Y-%m-%d %H:%M') %>