title: Rails where joins for different foreign key
body: <p>I have workorders and employees tables.  Each workorder has an employee assigned and a supervisor assigned.</p>
  
  <p>The workorder.rb has:</p>
  
  <pre><code>belongs_to :super, :class_name =&gt; "Employee", :foreign_key =&gt; "super_id"
  belongs_to :employee
  </code></pre>
  
  <p>I'm trying to create a where clause with a joins.  It works fine for joining the <code>:client</code>. But, the <code>:super</code> doesn't work.</p>
  
  <p>This is my current attempt:</p>
  
  <pre><code>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]}%")
  </code></pre>
  
  <p>I get back:</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>Thanks for the help!</p>