aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_many_through_association.rb
diff options
context:
space:
mode:
authorLuca Guidi <guidi.luca@gmail.com>2009-03-16 13:30:30 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-05-18 22:30:43 +0200
commitcef76c8af4705dc60f85a721e3a14adb99418d33 (patch)
treedb8489c51bfc1ae61e28aa8f9e9979d8bdcee6da /activerecord/lib/active_record/associations/has_many_through_association.rb
parentc5e109bbe766b0407a909361f18d2b87e9bfc75c (diff)
downloadrails-cef76c8af4705dc60f85a721e3a14adb99418d33.tar.gz
rails-cef76c8af4705dc60f85a721e3a14adb99418d33.tar.bz2
rails-cef76c8af4705dc60f85a721e3a14adb99418d33.zip
Ensure HasManyThroughAssociation#destroy delete orphan records [#2251 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/associations/has_many_through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb7
1 files changed, 7 insertions, 0 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 2dca84b911..e8dbae9011 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -17,6 +17,13 @@ module ActiveRecord
end
end
+ def destroy(*records)
+ transaction do
+ delete_records(flatten_deeper(records))
+ super
+ end
+ end
+
# Returns the size of the collection by executing a SELECT COUNT(*) query if the collection hasn't been loaded and
# calling collection.size if it has. If it's more likely than not that the collection does have a size larger than zero,
# and you need to fetch that collection afterwards, it'll take one fewer SELECT query if you use #length.