aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorTomas D'Stefano <tomasdestefi@gmail.com>2011-05-31 11:43:19 -0300
committerJon Leighton <j@jonathanleighton.com>2011-07-08 22:26:54 +0100
commitea4b94a7bf707d27af44701fa44ef5f916b84e01 (patch)
treeae5ef07b2cccc9f5dc0d8a1c0f453fe4123dd9ff /activerecord/lib/active_record/persistence.rb
parentdfec3737b05d22e6f298bcae0a8948a4b8803ebd (diff)
downloadrails-ea4b94a7bf707d27af44701fa44ef5f916b84e01.tar.gz
rails-ea4b94a7bf707d27af44701fa44ef5f916b84e01.tar.bz2
rails-ea4b94a7bf707d27af44701fa44ef5f916b84e01.zip
Destroy association habtm record before destroying the record itself. Fixes issue #402.
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index f425118f59..d9cd7987b0 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -79,6 +79,8 @@ module ActiveRecord
# Deletes the record in the database and freezes this instance to reflect
# that no changes should be made (since they can't be persisted).
def destroy
+ destroy_associations
+
if persisted?
IdentityMap.remove(self) if IdentityMap.enabled?
pk = self.class.primary_key
@@ -284,6 +286,11 @@ module ActiveRecord
end
private
+
+ # A hook to be overriden by association modules.
+ def destroy_associations
+ end
+
def create_or_update
raise ReadOnlyRecord if readonly?
result = new_record? ? create : update