0
我有工作單和僱員表。每臺工單都分配一名員工並分配一名主管。加入不同外鍵的導軌
的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"
感謝您的幫助!
感謝您的幫助! – Reddirt 2013-05-13 16:21:55