1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

touch operationg if used along with belongs_to will also be invoked on associated objects

This commit is contained in:
Neeraj Singh 2010-08-24 10:21:58 -04:00
parent 02aabbd19e
commit f460de1d23

View file

@ -208,10 +208,14 @@ module ActiveRecord
# If an attribute name is passed, that attribute is updated along with # If an attribute name is passed, that attribute is updated along with
# updated_at/on attributes. # updated_at/on attributes.
# #
# Examples:
#
# product.touch # updates updated_at/on # product.touch # updates updated_at/on
# product.touch(:designed_at) # updates the designed_at attribute and updated_at/on # product.touch(:designed_at) # updates the designed_at attribute and updated_at/on
#
# If used along with +belongs_to+ then +touch+ will invoke +touch+ method on associated object.
#
# Brake.belongs_to :car, :touch => true
# Car.belongs_to :corporation, :touch => true
# @brake.touch #=> will also invoke @brake.car.touch and @brake.car.corporation.touch
def touch(name = nil) def touch(name = nil)
attributes = timestamp_attributes_for_update_in_model attributes = timestamp_attributes_for_update_in_model
attributes << name if name attributes << name if name