Ruby on Rails Friday, January 27, 2017

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ace56579-2521-450e-b685-70e9fad10366%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment