Skip to content

Commit

Permalink
remove join table rows before removing owner row for habtm associatio…
Browse files Browse the repository at this point in the history
…ns, fixes#5674
  • Loading branch information
Hemant Kumar authored and tenderlove committed Sep 21, 2010
1 parent 96bd936 commit 953d129
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 953d129

Please sign in to comment.