diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2b988e89c..ec34126ac 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -77,11 +77,17 @@ class CoursesController < ApplicationController # 根据搜索关键字进一步筛选 if params[:search].present? # REDO:Extension - user_ids = User.includes(user_extension: :school).where("schools.name like ?", "%#{params[:search]}%").pluck(:id) - course_ids = CourseMember.includes(:user, :course).where("course_members.course_id in (?) and course_members.role in (1,2,3) - and CONCAT(users.lastname, users.firstname) like ?", @courses.map(&:id), "%#{params[:search]}%") - .pluck(:course_id) - @courses = @courses.where("name like ?", "%#{params[:search]}%").or(@courses.where(tea_id: user_ids)).or(@courses.where(id: course_ids)) + #user_ids = User.includes(user_extension: :school).where("schools.name like ?", "%#{params[:search]}%").pluck(:id) + #course_ids = CourseMember.includes(:user, :course).where("course_members.course_id in (?) and course_members.role in (1,2,3) + # and CONCAT(users.lastname, users.firstname) like ?", @courses.map(&:id), "%#{params[:search]}%") + # .pluck(:course_id) + #@courses = @courses.where("name like ?", "%#{params[:search]}%").or(@courses.where(tea_id: user_ids)).or(@courses.where(id: course_ids)) + # 6:21 daiao + sql = %Q{ + (course_members.role in (1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword + or schools.name like :keyword + } + @courses.includes(course_members: [user: [user_extension: :school]]).where(sql, keyword: "%#{params[:search]}%") end @courses_count = @courses.size