aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorHongli Lai (Phusion) <hongli@phusion.nl>2008-09-21 21:00:16 +0200
committerHongli Lai (Phusion) <hongli@phusion.nl>2008-09-21 21:00:20 +0200
commit353dc9d389f5d62c320c17eb9c7bb1acfc480952 (patch)
tree970bdf4795c0309c93ed6ee3326a9e8bc64cd67e /activerecord/lib/active_record
parent6547e6897cb07f73f05c13eef3bd6d211ec6dafd (diff)
downloadrails-353dc9d389f5d62c320c17eb9c7bb1acfc480952.tar.gz
rails-353dc9d389f5d62c320c17eb9c7bb1acfc480952.tar.bz2
rails-353dc9d389f5d62c320c17eb9c7bb1acfc480952.zip
Document some of the internals of associations handling.
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 5d91315aad..33457822ff 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1452,6 +1452,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]
@@ -1465,6 +1467,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.class.delete(association.id) unless association.nil?
end