aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorDimitri Krassovski <labria@startika.com>2009-03-06 19:11:13 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-03-06 19:11:13 +0000
commit984bc7a614852944808739fae09a654b6e62872e (patch)
treee5eede0f31d0b9cd8708c506fe81c12fe3f195df /activerecord/lib
parent4863634a157a8e4a0033734617253b42325daf34 (diff)
downloadrails-984bc7a614852944808739fae09a654b6e62872e.tar.gz
rails-984bc7a614852944808739fae09a654b6e62872e.tar.bz2
rails-984bc7a614852944808739fae09a654b6e62872e.zip
Ensure replacing has_one associations respects the supplied :dependent option. [#1305 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/has_one_association.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb
index 960323004d..b92cbbdeab 100644
--- a/activerecord/lib/active_record/associations/has_one_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_association.rb
@@ -29,8 +29,17 @@ module ActiveRecord
unless @target.nil? || @target == obj
if dependent? && !dont_save
- @target.destroy unless @target.new_record?
- @owner.clear_association_cache
+ case @reflection.options[:dependent]
+ when :delete
+ @target.delete unless @target.new_record?
+ @owner.clear_association_cache
+ when :destroy
+ @target.destroy unless @target.new_record?
+ @owner.clear_association_cache
+ when :nullify
+ @target[@reflection.primary_key_name] = nil
+ @target.save unless @owner.new_record? || @target.new_record?
+ end
else
@target[@reflection.primary_key_name] = nil
@target.save unless @owner.new_record? || @target.new_record?