This gem adds a class/scope method to your ActiveRecord models, that gives you the same functionality of update_all
but using the batching behavior of find_in_batches
.
It is a short cut for:
Model.find_in_batches do |batch|
ids = batch.map(&:id)
Model.where(id: ids).update_all
end
Add this line to your application's Gemfile:
gem 'update_in_batches'
And then execute:
$ bundle
Or install it yourself as:
$ gem install update_in_batches
class Project < ActiveRecord::Base
end
Project.where(active: true).update_in_batches(active: false)
- Fork it ( http://github.com//update_in_batches/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request