超管的单位列表无法按用户数排序

chromesetting
cxt 5 years ago
parent a9a8353ece
commit 20494971f2

@ -5,7 +5,7 @@ class Admins::SchoolsController < Admins::BaseController
schools = Admins::SchoolQuery.call(params) schools = Admins::SchoolQuery.call(params)
@schools = paginate schools.includes(:user_extensions) @schools = paginate schools
school_ids = @schools.map(&:id) school_ids = @schools.map(&:id)
@department_count = Department.where(school_id: school_ids).group(:school_id).count @department_count = Department.where(school_id: school_ids).group(:school_id).count

@ -17,6 +17,7 @@ class Admins::SchoolQuery < ApplicationQuery
if keyword if keyword
schools = schools.where('schools.name LIKE ?', "%#{keyword}%") schools = schools.where('schools.name LIKE ?', "%#{keyword}%")
end 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] custom_sort schools, params[:sort_by], params[:sort_direction]
end end
end end

@ -33,7 +33,7 @@
<td><%= school.province %></td> <td><%= school.province %></td>
<td><%= school.city %></td> <td><%= school.city %></td>
<td class="text-left"><%= school.address %></td> <td class="text-left"><%= school.address %></td>
<td><%= school.user_extensions.count %></td> <td><%= school.users_count %></td>
<td><%= @department_count.fetch(school.id, 0) %></td> <td><%= @department_count.fetch(school.id, 0) %></td>
<td><%= school.created_at&.strftime('%Y-%m-%d %H:%M') %></td> <td><%= school.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td> <td>

Loading…
Cancel
Save