From 498d8ff72eded86fb1064205332e0a91b1dacece Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 14 Sep 2007 07:29:22 +0000 Subject: Fix association writer with :dependent => :nullify. Closes #7314. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7477 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../associations/has_many_association.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'activerecord/lib/active_record/associations/has_many_association.rb') diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index d385691967..d07d460b0a 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -125,14 +125,17 @@ module ActiveRecord end def delete_records(records) - if @reflection.options[:dependent] - records.each { |r| r.destroy } - else - ids = quoted_record_ids(records) - @reflection.klass.update_all( - "#{@reflection.primary_key_name} = NULL", - "#{@reflection.primary_key_name} = #{@owner.quoted_id} AND #{@reflection.klass.primary_key} IN (#{ids})" - ) + case @reflection.options[:dependent] + when :destroy + records.each(&:destroy) + when :delete_all + @reflection.klass.delete(records.map(&:id)) + else + ids = quoted_record_ids(records) + @reflection.klass.update_all( + "#{@reflection.primary_key_name} = NULL", + "#{@reflection.primary_key_name} = #{@owner.quoted_id} AND #{@reflection.klass.primary_key} IN (#{ids})" + ) end end -- cgit v1.2.3