Model.find(ids)
Caveat: This will give the objects back in an array. However, if you want to run ActiveRecord methods on this, better to use this:
Class.where(id: ids)
Then, you can chain methods like so:
Class.where(id: ids).update_all(updated_at: Time.now)
Be careful!
update_all
does NOT run validations. But it is incredibly useful for updating several records without instantiating all of the objects. This is a straight sequel query, hence no callbacks.
No comments:
Post a Comment