Search code examples
ruby-on-railsrails-migrations

Rails Unknown key: :conditions. Valid keys are: :start, :batch_size


I wrote a migration that is pretty beefy, It needs to run over several collections and then do a find_or_intialize_by I am doing this within a single transaction and it's taking 80+ seconds to run the query. I want to now try speed this up by using find_each.

ActiveRecord::Base.transaction do
  StudentApplication.find_each(:conditions => "force_review is true") do |app|
    ....
  end
end

I am getting the following:

== 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

Looking at this tutorial around using find_each, I see it takes a hash argument that allows you to specify a condition to the query, I wanted to take advantage of that to filter the results before running the find_each.

we are using Rails 4.1.14.2 and ruby 2.3.0p0, has this option now been deprecated? Or am I doing something wrong?


Solution

  • The link you provide is for Rails 2.3.8.
    You can see message that this find_each is deprecated.
    enter image description here You should use this link.
    As you can see there is no conditions key that is why you are getting the error.