Ruby On Rails : ActiveRecord : Batch update/create : Updating/Creating Multiple records at the same time

Sometime you may require to update multiple rows in your tables with different data. If you were looking for updating all record with same data then you should go for update_all method.

Batch update

 # Updating multiple records; different col with different data:
  people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy" } }
  Person.update(people.keys, people.values)

Continue reading

Advertisements