Skip to content
This repository
Browse code

fix #delete_all with habtm with :delete_sql

  • Loading branch information...
commit 855fabca669f1a57c70bfa7bfc396495018e4a5c 1 parent b98d1e2
Jon Leighton jonleighton authored
1  activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -44,6 +44,7 @@ def count_records
44 44
45 45 def delete_records(records, method)
46 46 if sql = options[:delete_sql]
  47 + records = load_target if records == :all
47 48 records.each { |record| owner.connection.delete(interpolate(sql, record)) }
48 49 else
49 50 relation = join_table
6 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -379,6 +379,12 @@ def test_deleting_array_with_sql
379 379 assert_equal 0, active_record.developers_by_sql(true).size
380 380 end
381 381
  382 + def test_deleting_all_with_sql
  383 + project = Project.find(1)
  384 + project.developers_by_sql.delete_all
  385 + assert_equal 0, project.developers_by_sql.size
  386 + end
  387 +
382 388 def test_deleting_all
383 389 david = Developer.find(1)
384 390 david.projects.reload

0 comments on commit 855fabc

Please sign in to comment.
Something went wrong with that request. Please try again.