Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Added touch to associations guide

  • Loading branch information...
commit 0271d9bda7e4c549f46131d384f9ce307d01ad83 1 parent 5bc635b
@ffmike ffmike authored
Showing with 24 additions and 0 deletions.
  1. +24 −0 railties/guides/source/association_basics.textile
24 railties/guides/source/association_basics.textile
@@ -600,6 +600,7 @@ The +belongs_to+ association supports these options:
* +:polymorphic+
* +:readonly+
* +:select+
+* +:touch+
* +:validate+
h6. +:autosave+
@@ -736,6 +737,28 @@ The +:select+ option lets you override the SQL +SELECT+ clause that is used to r
TIP: If you set the +:select+ option on a +belongs_to+ association, you should also set the +foreign_key+ option to guarantee the correct results.
+h6. +:touch+
+If you set the +:touch+ option to +:true+, then the +updated_at+ or +updated_on+ timestamp on the associated object will be set to the current time whenever this object is saved or destroyed:
+class Order < ActiveRecord::Base
+ belongs_to :customer, :touch => true
+class Customer < ActiveRecord::Base
+ has_many :orders
+In this case, saving or destroying an order will update the timestamp on the associated customer. You can also specify a particular timestamp attribute to update:
+class Order < ActiveRecord::Base
+ belongs_to :customer, :touch => :orders_updated_at
h6. +:validate+
If you set the +:validate+ option to +true+, then associated objects will be validated whenever you save this object. By default, this is +false+: associated objects will not be validated when this object is saved.
@@ -1775,6 +1798,7 @@ h3. Changelog
"Lighthouse ticket":
+* April 19, 2009: Added +:touch+ option to +belongs_to+ associations by "Mike Gunderloy":credits.html#mgunderloy
* February 1, 2009: Added +:autosave+ option "Mike Gunderloy":credits.html#mgunderloy
* September 28, 2008: Corrected +has_many :through+ diagram, added polymorphic diagram, some reorganization by "Mike Gunderloy":credits.html#mgunderloy . First release version.
* September 22, 2008: Added diagrams, misc. cleanup by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication)

0 comments on commit 0271d9b

Please sign in to comment.
Something went wrong with that request. Please try again.