ActiveRecord.update_each / updated_each!

26 views
Skip to first unread message

Dorian Marié

unread,
Jan 28, 2017, 2:14:57 AM1/28/17
to Ruby on Rails: Talk
What do you think about adding update_each and update_each! to ActiveRecord?

Basically it would make it easier to switch from update_all but triggering the callbacks (and could be later optimized, where `each { |m| m.update(...) }` is very difficult to optimize from the Rails-side.

A simple implementation could be:

```
class ActiveRecord::Base
  def self.update_each(updates)
    find_each { |model| model.update(updates) }
  end

  def self.update_each!(updates)
    find_each { |model| model.update!(updates) }
  end
end
```

-
Dorian
Programmer
Reply all
Reply to author
Forward
0 new messages