0

我升级到 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_tohas_many语句都设置正确,并且在我以前的 Rails 版本中有效(但不确定是哪一个)。

谁能告诉我如何让它再次工作?

谢谢你的帮助。

4

1 回答 1

1

我相信你必须加入projects表:

..
    elsif person_id
      joins(:projects).where("projects.person_id = ?", person_id)     
    else
..
于 2013-01-19T23:22:20.260 回答