From a2932784bb71e72a78c32819ebd7ed2bed551e3e Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 5 Oct 2008 22:16:26 +0100 Subject: Merge docrails --- activerecord/lib/active_record/associations.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations.rb') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 3f8ec4d09c..d1a0b2f96a 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -955,8 +955,6 @@ module ActiveRecord # destroyed. This requires that a column named #{table_name}_count (such as +comments_count+ for a belonging Comment class) # is used on the associate class (such as a Post class). You can also specify a custom counter cache column by providing # a column name instead of a +true+/+false+ value to this option (e.g., :counter_cache => :my_custom_counter.) - # When creating a counter cache column, the database statement or migration must specify a default value of 0, failing to do - # this results in a counter with +NULL+ value, which will never increment. # Note: Specifying a counter cache will add it to that model's list of readonly attributes using +attr_readonly+. # [:include] # Specify second-order associations that should be eager loaded when this object is loaded. @@ -1479,6 +1477,8 @@ module ActiveRecord end end + # Creates before_destroy callback methods that nullify, delete or destroy + # has_one associated objects, according to the defined :dependent rule. def configure_dependency_for_has_one(reflection) if reflection.options.include?(:dependent) case reflection.options[:dependent] @@ -1492,6 +1492,10 @@ module ActiveRecord when :delete method_name = "has_one_dependent_delete_for_#{reflection.name}".to_sym define_method(method_name) do + # Retrieve the associated object and delete it. The retrieval + # is necessary because there may be multiple associated objects + # with foreign keys pointing to this object, and we only want + # to delete the correct one, not all of them. association = send(reflection.name) association.delete unless association.nil? end -- cgit v1.2.3