mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
remove join table rows before removing owner row for habtm associations, fixes#5674
This commit is contained in:
committed by
Aaron Patterson
parent
96bd936b64
commit
953d129bb2
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user