remove join table rows before removing owner row for habtm associations, fixes#5674

This commit is contained in:
Hemant Kumar
2010-09-22 01:30:10 +05:30
committed by Aaron Patterson
parent 96bd936b64
commit 953d129bb2
2 changed files with 2 additions and 2 deletions

View File

@@ -1416,8 +1416,8 @@ module ActiveRecord
include Module.new {
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def destroy # def destroy
super # super
#{reflection.name}.clear # posts.clear
super # super
end # end
RUBY
}

View File

@@ -425,7 +425,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
def test_removing_associations_on_destroy
david = DeveloperWithBeforeDestroyRaise.find(1)
assert !david.projects.empty?
assert_nothing_raised { david.destroy }
assert_raise(RuntimeError) { david.destroy }
assert david.projects.empty?
assert DeveloperWithBeforeDestroyRaise.connection.select_all("SELECT * FROM developers_projects WHERE developer_id = 1").empty?
end