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:
parent
a1dd00810c
commit
dcc576df8f
2 changed files with 7 additions and 0 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue