私はworkordersとemployeesテーブルを持っています。各ワークオーダーには、割り当てられた従業員とスーパーバイザーが割り当てられています。
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"
助けてくれてありがとう!