module Mongoid::Relations::Touchable
def touch(field = nil)
- Since: - 3.0.0
Returns:
-
(true/false)- false if record is new_record otherwise true.
Parameters:
-
field(Symbol) -- The name of an additional field to update.
Other tags:
- Note: - This will not autobuild relations if those options are set.
Other tags:
- Example: Update the updated_at and provided timestamps. -
Example: Update the updated_at timestamp. -
def touch(field = nil) return false if _root.new_record? current = Time.now field = database_field_name(field) write_attribute(:updated_at, current) if respond_to?("updated_at=") write_attribute(field, current) if field touches = touch_atomic_updates(field) unless touches.empty? selector = atomic_selector _root.collection.find(selector).update_one(positionally(selector, touches)) end run_callbacks(:touch) true end