aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-09-11 11:23:11 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-09-11 11:23:30 -0700
commit7e0cac156eae758a81b2f0f4ac1b18afd7e5354e (patch)
tree9ce75e20518f44dd0dfffb67f7a69ebdf9ec47ce /activerecord/lib/active_record/associations
parent233c6d4c298434544e349a559906f5fa1883e070 (diff)
downloadrails-7e0cac156eae758a81b2f0f4ac1b18afd7e5354e.tar.gz
rails-7e0cac156eae758a81b2f0f4ac1b18afd7e5354e.tar.bz2
rails-7e0cac156eae758a81b2f0f4ac1b18afd7e5354e.zip
fix deleting join models with no pk
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index a74dd1cdab..56331bbb0b 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -140,7 +140,21 @@ module ActiveRecord
case method
when :destroy
- count = scope.destroy_all.length
+ if scope.klass.primary_key
+ count = scope.destroy_all.length
+ else
+ scope.to_a.each do |record|
+ record.run_callbacks :destroy
+ end
+
+ arel = scope.arel
+
+ stmt = Arel::DeleteManager.new arel.engine
+ stmt.from scope.klass.arel_table
+ stmt.wheres = arel.constraints
+
+ count = scope.klass.connection.delete(stmt, 'SQL', scope.bind_values)
+ end
when :nullify
count = scope.update_all(source_reflection.foreign_key => nil)
else