From 47d252f9928568620844edce2161acd457c352c0 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sun, 7 Mar 2010 21:53:21 -0300 Subject: Fix associations to call :destroy or :delete based on the right :dependent option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activerecord/lib/active_record/associations.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index e1a9c54e5d..b69577f8dd 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1544,12 +1544,12 @@ module ActiveRecord when :destroy, :delete define_method(method_name) do association = send(reflection.name) - association.destroy unless association.nil? + association.send(name) if association end when :nullify define_method(method_name) do association = send(reflection.name) - association.update_attribute(reflection.primary_key_name, nil) unless association.nil? + association.update_attribute(reflection.primary_key_name, nil) if association end else raise ArgumentError, "The :dependent option expects either :destroy, :delete or :nullify (#{reflection.options[:dependent].inspect})" @@ -1570,7 +1570,7 @@ module ActiveRecord method_name = :"belongs_to_dependent_#{name}_for_#{reflection.name}" define_method(method_name) do association = send(reflection.name) - association.destroy unless association.nil? + association.send(name) if association end after_destroy method_name end -- cgit v1.2.3