我有工单和员工表。每个工单都分配了一名员工和一名主管。
workorder.rb 有:
belongs_to :super, :class_name => "Employee", :foreign_key => "super_id"
belongs_to :employee
我正在尝试创建一个带有连接的 where 子句。它适用于加入:client
. 但是,这:super
不起作用。
这是我目前的尝试:
workorders = workorders.joins(:client,:super).where("wonum like :search or description like :search or clients.client_name like :search or super.employee_full_name like :search ", search: "%#{params[:sSearch]}%")
我回来了:
SELECT COUNT(*) FROM "workorders" INNER JOIN "clients" ON "clients"."id" = "workorders"."client_id" INNER JOIN "employees" ON "employees"."id" = "workorders"."super_id" WHERE (wonum like '%CHUCK%' or description like '%CHUCK%' or clients.client_name like '%CHUCK%' or super.employee_full_name like '%CHUCK%' ) AND (wostatus_id NOT IN (231,230,9263,9264,232))
Completed 500 Internal Server Error in 236ms
ActiveRecord::StatementInvalid - PG::Error: ERROR: missing FROM-clause entry for table "super"
谢谢您的帮助!