Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8367

Show
Ignore:
Timestamp:
12/10/07 09:12:18 (9 months ago)
Author:
bitsweat
Message:

Update destroy_all and delete_all documentation to better describe their tradeoffs. Closes #10447.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r8362 r8367  
    11*SVN* 
    22 
    3 * Document Active Record exceptions.  #10444 [Michael Klishin] 
     3* Documentation: Active Record exceptions, destroy_all and delete_all.  #10444, #10447 [Michael Klishin] 
    44 
    55 
  • trunk/activerecord/lib/active_record/base.rb

    r8362 r8367  
    679679      end 
    680680 
    681       # Destroys the objects for all the records that match the +conditions+ by instantiating each object and calling 
    682       # the destroy method. Example: 
     681      # Destroys the records matching +conditions+ by instantiating each record and calling the destroy method. 
     682      # This means at least 2*N database queries to destroy N records, so avoid destroy_all if you are deleting 
     683      # many records. If you want to simply delete records without worrying about dependent associations or 
     684      # callbacks, use the much faster +delete_all+ method instead. 
     685      # 
     686      # ==== Options 
     687      # 
     688      # +conditions+   Conditions are specified the same way as with +find+ method. 
     689      # 
     690      # ==== Example 
     691      # 
    683692      #   Person.destroy_all "last_login < '2004-04-04'" 
     693      # 
     694      # This loads and destroys each person one by one, including its dependent associations and before_ and 
     695      # after_destroy callbacks. 
    684696      def destroy_all(conditions = nil) 
    685697        find(:all, :conditions => conditions).each { |object| object.destroy } 
    686698      end 
    687699 
    688       # Deletes all the records that match the +conditions+ without instantiating the objects first (and hence not 
    689       # calling the destroy method). Example: 
     700      # Deletes the records matching +conditions+ without instantiating the records first, and hence not 
     701      # calling the destroy method and invoking callbacks. This is a single SQL query, much more efficient 
     702      # than destroy_all. 
     703      # 
     704      # ==== Options 
     705      # 
     706      # +conditions+   Conditions are specified the same way as with +find+ method. 
     707      # 
     708      # ==== Example 
     709      # 
    690710      #   Post.delete_all "person_id = 5 AND (category = 'Something' OR category = 'Else')" 
     711      # 
     712      # This deletes the affected posts all at once with a single DELETE query. If you need to destroy dependent 
     713      # associations or call your before_ or after_destroy callbacks, use the +destroy_all+ method instead. 
    691714      def delete_all(conditions = nil) 
    692715        sql = "DELETE FROM #{quoted_table_name} "