Skip to content
This repository
Browse code

fixing documentation just a little bit

  • Loading branch information...
commit 4f63294b0f4a428ed4dff172067ec114b86a1c25 1 parent 3d70998
Neeraj Singh authored July 31, 2010
4  activerecord/lib/active_record/associations.rb
@@ -114,7 +114,7 @@ module Associations # :nodoc:
114 114
     autoload :HasOneAssociation, 'active_record/associations/has_one_association'
115 115
     autoload :HasOneThroughAssociation, 'active_record/associations/has_one_through_association'
116 116
 
117  
-    # Clears out the association cache
  117
+    # Clears out the association cache.
118 118
     def clear_association_cache #:nodoc:
119 119
       self.class.reflect_on_all_associations.to_a.each do |assoc|
120 120
         instance_variable_set "@#{assoc.name}", nil
@@ -122,7 +122,7 @@ def clear_association_cache #:nodoc:
122 122
     end
123 123
 
124 124
     private
125  
-      # Gets the specified association instance if it responds to :loaded?, nil otherwise.
  125
+      # Returns the specified association instance if it responds to :loaded?, nil otherwise.
126 126
       def association_instance_get(name)
127 127
         ivar = "@#{name}"
128 128
         if instance_variable_defined?(ivar)
34  activerecord/lib/active_record/autosave_association.rb
@@ -4,14 +4,13 @@ module ActiveRecord
4 4
   # = Active Record Autosave Association
5 5
   # 
6 6
   # AutosaveAssociation is a module that takes care of automatically saving
7  
-  # your associations when the parent is saved. In addition to saving, it
8  
-  # also destroys any associations that were marked for destruction.
  7
+  # associacted records when parent is saved. In addition to saving, it
  8
+  # also destroys any associated records that were marked for destruction.
9 9
   # (See mark_for_destruction and marked_for_destruction?)
10 10
   #
11 11
   # Saving of the parent, its associations, and the destruction of marked
12 12
   # associations, all happen inside 1 transaction. This should never leave the
13  
-  # database in an inconsistent state after, for instance, mass assigning
14  
-  # attributes and saving them.
  13
+  # database in an inconsistent state.
15 14
   #
16 15
   # If validations for any of the associations fail, their error messages will
17 16
   # be applied to the parent.
@@ -21,8 +20,6 @@ module ActiveRecord
21 20
   #
22 21
   # === One-to-one Example
23 22
   #
24  
-  # Consider a Post model with one Author:
25  
-  #
26 23
   #   class Post
27 24
   #     has_one :author, :autosave => true
28 25
   #   end
@@ -155,11 +152,12 @@ def #{type}(name, options = {})
155 152
         CODE
156 153
       end
157 154
 
158  
-      # Adds a validate and save callback for the association as specified by
  155
+      # Adds validation and save callbacks for the association as specified by
159 156
       # the +reflection+.
160 157
       #
161  
-      # For performance reasons, we don't check whether to validate at runtime,
162  
-      # but instead only define the method and callback when needed. However,
  158
+      # For performance reasons, we don't check whether to validate at runtime.
  159
+      # However the validation and callback methods are lazy and those methods
  160
+      # get created when they are invoked for the very first time.  However,
163 161
       # this can change, for instance, when using nested attributes, which is
164 162
       # called _after_ the association has been defined. Since we don't want
165 163
       # the callbacks to get defined multiple times, there are guards that
@@ -197,14 +195,15 @@ def add_autosave_association_callbacks(reflection)
197 195
       end
198 196
     end
199 197
 
200  
-    # Reloads the attributes of the object as usual and removes a mark for destruction.
  198
+    # Reloads the attributes of the object as usual and clears <tt>marked_for_destruction/tt> flag.
201 199
     def reload(options = nil)
202 200
       @marked_for_destruction = false
203 201
       super
204 202
     end
205 203
 
206 204
     # Marks this record to be destroyed as part of the parents save transaction.
207  
-    # This does _not_ actually destroy the record yet, rather it will be destroyed when <tt>parent.save</tt> is called.
  205
+    # This does _not_ actually destroy the record instantly, rather child record will be destroyed 
  206
+    # when <tt>parent.save</tt> is called.
208 207
     #
209 208
     # Only useful if the <tt>:autosave</tt> option on the parent is enabled for this associated model.
210 209
     def mark_for_destruction
@@ -249,7 +248,7 @@ def nested_records_changed_for_autosave?
249 248
     end
250 249
     
251 250
     # Validate the association if <tt>:validate</tt> or <tt>:autosave</tt> is
252  
-    # turned on for the association specified by +reflection+.
  251
+    # turned on for the association.
253 252
     def validate_single_association(reflection)
254 253
       if (association = association_instance_get(reflection.name)) && !association.target.nil?
255 254
         association_valid?(reflection, association)
@@ -357,14 +356,9 @@ def save_has_one_association(reflection)
357 356
       end
358 357
     end
359 358
 
360  
-    # Saves the associated record if it's new or <tt>:autosave</tt> is enabled
361  
-    # on the association.
362  
-    #
363  
-    # In addition, it will destroy the association if it was marked for
364  
-    # destruction with mark_for_destruction.
  359
+    # Saves the associated record if it's new or <tt>:autosave</tt> is enabled.
365 360
     #
366  
-    # This all happens inside a transaction, _if_ the Transactions module is included into
367  
-    # ActiveRecord::Base after the AutosaveAssociation module, which it does by default.
  361
+    # In addition, it will destroy the association if it was marked for destruction.
368 362
     def save_belongs_to_association(reflection)
369 363
       if (association = association_instance_get(reflection.name)) && !association.destroyed?
370 364
         autosave = reflection.options[:autosave]
@@ -384,4 +378,4 @@ def save_belongs_to_association(reflection)
384 378
       end
385 379
     end
386 380
   end
387  
-end
  381
+end

0 notes on commit 4f63294

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