Rails 未知密钥::条件。有效键是::start, :batch_size
Rails Unknown key: :conditions. Valid keys are: :start, :batch_size
我写了一个非常强大的迁移,它需要 运行 多个集合然后执行 find_or_intialize_by
我在单个事务中执行此操作并且需要 80 多秒才能 运行查询。我现在想尝试使用 find_each
.
来加快速度
ActiveRecord::Base.transaction do
StudentApplication.find_each(:conditions => "force_review is true") do |app|
....
end
end
我得到以下信息:
== 20160920133013 MoveForceReviewFieldsToCcSubmission: migrating ==============
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Unknown key: :conditions. Valid keys are: :start, :batch_size/Users/Nexus/Work/prodigy/db/migrate/20160920133013_move_force_review_fields_to_cc_submission.rb:4:in `block in change'
/Users/Nexus/Work/prodigy/db/migrate/20160920133013_move_force_review_fields_to_cc_submission.rb:3:in `change'
/Users/Nexus/.rbenv/versions/2.3.0/bin/bundle:23:in `load'
/Users/Nexus/.rbenv/versions/2.3.0/bin/bundle:23:in `<main>'
ArgumentError: Unknown key: :conditions. Valid keys are: :start, :batch_size
查看 this tutorial around 使用 find_each
,我看到它需要一个散列参数,允许您为查询指定条件,我想利用它在 运行宁 find_each
.
我们正在使用 Rails 4.1.14.2
和 ruby 2.3.0p0
,现在是否已弃用此选项?还是我做错了什么?
您提供的 link 用于 Rails 2.3.8
。
您可以看到此 find_each
已弃用的消息。
你应该使用 this link.
如您所见,没有 conditions
键,这就是您收到错误的原因。
你可以这样使用它
StudentApplication.where(force_review: true).find_each do |app|
....
end
我写了一个非常强大的迁移,它需要 运行 多个集合然后执行 find_or_intialize_by
我在单个事务中执行此操作并且需要 80 多秒才能 运行查询。我现在想尝试使用 find_each
.
ActiveRecord::Base.transaction do
StudentApplication.find_each(:conditions => "force_review is true") do |app|
....
end
end
我得到以下信息:
== 20160920133013 MoveForceReviewFieldsToCcSubmission: migrating ==============
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Unknown key: :conditions. Valid keys are: :start, :batch_size/Users/Nexus/Work/prodigy/db/migrate/20160920133013_move_force_review_fields_to_cc_submission.rb:4:in `block in change'
/Users/Nexus/Work/prodigy/db/migrate/20160920133013_move_force_review_fields_to_cc_submission.rb:3:in `change'
/Users/Nexus/.rbenv/versions/2.3.0/bin/bundle:23:in `load'
/Users/Nexus/.rbenv/versions/2.3.0/bin/bundle:23:in `<main>'
ArgumentError: Unknown key: :conditions. Valid keys are: :start, :batch_size
查看 this tutorial around 使用 find_each
,我看到它需要一个散列参数,允许您为查询指定条件,我想利用它在 运行宁 find_each
.
我们正在使用 Rails 4.1.14.2
和 ruby 2.3.0p0
,现在是否已弃用此选项?还是我做错了什么?
您提供的 link 用于 Rails 2.3.8
。
您可以看到此 find_each
已弃用的消息。
如您所见,没有 conditions
键,这就是您收到错误的原因。
你可以这样使用它
StudentApplication.where(force_review: true).find_each do |app|
....
end