Permalink
Browse files

touch operationg if used along with belongs_to will also be invoked o…

…n associated objects
  • Loading branch information...
1 parent 02aabbd commit f460de1d237e02fdbc3006bc91813efe7837f576 Neeraj Singh committed Aug 24, 2010
Showing with 6 additions and 2 deletions.
  1. +6 −2 activerecord/lib/active_record/persistence.rb
View
8 activerecord/lib/active_record/persistence.rb
@@ -208,10 +208,14 @@ def reload(options = nil)
# If an attribute name is passed, that attribute is updated along with
# updated_at/on attributes.
#
- # Examples:
- #
# product.touch # updates 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)
attributes = timestamp_attributes_for_update_in_model
attributes << name if name

0 comments on commit f460de1

Please sign in to comment.