delete_all doesn't work when chained with joins
Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6555 Created by Akira Matsuda - 2011-03-10 10:10:09 UTC
Given a case when Pet.has_many :toys
, the following delete_all
fails:
Pet.joins(:toys).where(:toys => {:name => 'Bone'}).delete_all
bacause current Arel implementation ignores joins
parameter and tries to execute the following SQL.
DELETE FROM "pets" WHERE "toys"."name" = 'Bone'
Attached is a patch that avoids this error by constructing a subquery only when delete_all
is chained with joins
.