Where子句不再适用于Rails 3.2.3?

时间:2013-01-19 12:38:07

标签: ruby-on-rails-3 ruby-on-rails-3.2

我升级到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版本中有效(不确定是哪一个)。

有人能告诉我如何重新开始工作吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我相信你必须加入projects表:

..
    elsif person_id
      joins(:projects).where("projects.person_id = ?", person_id)     
    else
..