我升级到 Rails 3.2.3,突然这段代码不再工作:
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
这是触发错误的最后一个where
子句:
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')
在我的模型中,所有belongs_to
和has_many
语句都设置正确,并且在我以前的 Rails 版本中有效(但不确定是哪一个)。
谁能告诉我如何让它再次工作?
谢谢你的帮助。