单位列表搜索问题

chromesetting
daiao 5 years ago
parent 1b2533ca9f
commit 47db48627b

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

@ -17,11 +17,6 @@ class Admins::SchoolQuery < ApplicationQuery
if keyword
schools = schools.where('schools.name LIKE ?', "%#{keyword}%")
end
Rails.logger.info("#########school_name: ##{schools.first.name}")
Rails.logger.info("#########school_id: ##{schools.first.id}")
schools = schools.joins("right join user_extensions on user_extensions.school_id = schools.id").group("schools.id")
Rails.logger.info("#########school_id: ##{schools.first.id}")
schools = schools.select('schools.*, COUNT(*) AS users_count')
custom_sort schools, params[:sort_by], params[:sort_direction]
end
end

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

Loading…
Cancel
Save