From 544152cdf60aee6287003304fefcaa19a9958d69 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 09:57:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E9=A6=96=E9=A1=B5=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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