instance method
touch_all
Ruby on Rails 8.1.2
Since v6.0.6Signature
touch_all(*names, time: nil)
Touches all records in the current relation, setting the updated_at/updated_on attributes to the current time or the time specified. It does not instantiate the involved models, and it does not trigger Active Record callbacks or validations. This method can be passed attribute names and an optional time argument. If attribute names are passed, they are updated along with updated_at/updated_on attributes. If no time argument is passed, the current time is used as default.
Examples
# Touch all records
Person.all.touch_all
# => "UPDATE \"people\" SET \"updated_at\" = '2018-01-04 22:55:23.132670'"
# Touch multiple records with a custom attribute
Person.all.touch_all(:created_at)
# => "UPDATE \"people\" SET \"updated_at\" = '2018-01-04 22:55:23.132670', \"created_at\" = '2018-01-04 22:55:23.132670'"
# Touch multiple records with a specified time
Person.all.touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
# => "UPDATE \"people\" SET \"updated_at\" = '2020-05-16 00:00:00'"
# Touch records with scope
Person.where(name: 'David').touch_all
# => "UPDATE \"people\" SET \"updated_at\" = '2018-01-04 22:55:23.132670' WHERE \"people\".\"name\" = 'David'"
Parameters
-
namesrest -
timekey = nil
Source
# File activerecord/lib/active_record/relation.rb, line 991
def touch_all(*names, time: nil)
update_all model.touch_attributes_with_time(*names, time: time)
end
Defined in activerecord/lib/active_record/relation.rb line 991
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Relation