Q:

Where clause no longer working in Rails 3.2.3?

I upgraded to Rails 3.2.3 and all of a sudden this code no longer works:
  def self.search(query, project_id, person_id)
    if query
      where("number LIKE ?", "%#{query}%")
    elsif project_id
      where("project_id LIKE ?", project_id)
    elsif person_id
      where("projects.person_id = ?", person_id)     
    else
      scoped
    end
  end

It is the last where clause that triggers the error:
SQLite3::SQLException: no such column: projects.person_id: SELECT COUNT(DISTINCT "invoices"."id") FROM "invoices" LEFT OUTER JOIN "items" ON "items"."invoice_id" = "invoices"."id" LEFT OUTER JOIN "payments" ON "payments"."invoice_id" = "invoices"."id" WHERE "invoices"."user_id" = 1 AND (projects.person_id = '1')

In my models all the belongs_to and has_many statements are set correctly and it worked in my previous version of Rails (not sure which one that was though).
Can anybody tell me how to get this working again?
Thanks for any help.

A:

I believe you'll have to join the projects table:
..
    elsif person_id
      joins(:projects).where("projects.person_id = ?", person_id)     
    else
..

