diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2010-03-07 21:53:21 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-03-09 00:11:34 +0100 |
commit | 47d252f9928568620844edce2161acd457c352c0 (patch) | |
tree | d8dce8dbd2c2c973bd792a51dafbc9d0c430a1c3 /activerecord/lib/active_record | |
parent | 8e9d9232b0c3d96c662762e13848c275a86c0c61 (diff) | |
download | rails-47d252f9928568620844edce2161acd457c352c0.tar.gz rails-47d252f9928568620844edce2161acd457c352c0.tar.bz2 rails-47d252f9928568620844edce2161acd457c352c0.zip |
Fix associations to call :destroy or :delete based on the right :dependent option
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 6 |
1 files changed, 3 insertions, 3 deletions
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 |