3

when i update all the authors papertrail won't create record in version table b'coz update_all wan't trigger ActiveRecord callbacks

Billing.update_all( "author = 'David'", "title LIKE '%Rails%'" )
dr. strange
  • 665
  • 7
  • 22
  • 2
    possible duplicate of [How to update all when you need callbacks fired?](http://stackoverflow.com/questions/6931812/how-to-update-all-when-you-need-callbacks-fired) – Rajdeep Singh Mar 09 '15 at 12:32

1 Answers1

3

ActiveRecord update_all does not instantiate the objects and does not trigger callbacks. As of version 6.0.2 Airblade still will not insert new versions in the versions table when using update_all or batch updates. See issue #337

If you're dealing with a small amount of data at a time, you can trigger callbacks by calling update on the relation in Rails 5 docs.

Billing.where("title LIKE '%Rails%'").update(author: 'David')

If you're using a previous version of Rails, you'll need to loop through the collection of objects and call update on each instance.

RKelley
  • 576
  • 6
  • 16