提交 953d129b 编写于 作者: H Hemant Kumar 提交者: Aaron Patterson

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

上级 96bd936b
......@@ -1416,8 +1416,8 @@ def has_and_belongs_to_many(association_id, options = {}, &extension)
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
}
......
......@@ -425,7 +425,7 @@ def test_deleting_all
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册