1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

fix #delete_all with habtm with :delete_sql

This commit is contained in:
Jon Leighton 2012-05-18 21:11:34 +01:00
parent a1dd00810c
commit dcc576df8f
2 changed files with 7 additions and 0 deletions

View file

@ -40,6 +40,7 @@ module ActiveRecord
def delete_records(records, method) def delete_records(records, method)
if sql = options[:delete_sql] if sql = options[:delete_sql]
records = load_target if records == :all
records.each { |record| owner.connection.delete(interpolate(sql, record)) } records.each { |record| owner.connection.delete(interpolate(sql, record)) }
else else
relation = join_table relation = join_table

View file

@ -380,6 +380,12 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal 0, active_record.developers_by_sql(true).size assert_equal 0, active_record.developers_by_sql(true).size
end end
def test_deleting_all_with_sql
project = Project.find(1)
project.developers_by_sql.delete_all
assert_equal 0, project.developers_by_sql.size
end
def test_deleting_all def test_deleting_all
david = Developer.find(1) david = Developer.find(1)
david.projects.reload david.projects.reload