【发布时间】:2014-07-14 22:50:15
【问题描述】:
从 Rails 3 升级到 Rail 4 时,我收到“ActiveRecord 关联中范围块和已弃用的查找器选项的无效组合”错误。关于这个问题有几篇文章,其中一些使用的格式如下:
has_many :readable_exams,
-> { where trashed_at: nil },
through: :student
但是,当我使用这种格式时,我收到了无效错误。另一方面,当我这样做时:
has_many :readable_exams,
-> { where(trashed_at: nil)
.through(:student) }
没有错误被抛出。谁能解释为什么 through 在第一种情况下会引发错误,而不是在第二种情况下?
编辑: 事实证明,我的错误来自一个包装了我之前忽略的 has_many 的 with_options 块。
with_options source: :exams,
primary_key: "student_id",
group: "exams.id" do |user| # This was throwing the error
user.has_many :readable_exams,
-> { where trashed_at: nil },
through: :student
...
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 scope