aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_collection.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-30 19:07:08 +0000
committerJon Leighton <j@jonathanleighton.com>2011-02-07 23:35:05 +0000
commitd55406d2e991056b08f69eb68bcf9b17da807b6c (patch)
tree239edd0fef82a334309734b92639740a7e7c73db /activerecord/lib/active_record/associations/association_collection.rb
parent5f1ea2a26b6e29f235e132d565b53f12e0234c66 (diff)
downloadrails-d55406d2e991056b08f69eb68bcf9b17da807b6c.tar.gz
rails-d55406d2e991056b08f69eb68bcf9b17da807b6c.tar.bz2
rails-d55406d2e991056b08f69eb68bcf9b17da807b6c.zip
Make record.association.destroy(*records) on habtm and hm:t only delete records in the join table. This is to make the destroy method more consistent across the different types of associations. For more details see the CHANGELOG entry.
Diffstat (limited to 'activerecord/lib/active_record/associations/association_collection.rb')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 2811f53424..9bd59132f5 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -192,7 +192,7 @@ module ActiveRecord
def destroy(*records)
records = find(records) if records.any? {|record| record.kind_of?(Fixnum) || record.kind_of?(String)}
remove_records(records) do |_records, old_records|
- old_records.each { |record| record.destroy }
+ delete_records(old_records, :destroy) if old_records.any?
end
load_target
@@ -462,6 +462,12 @@ module ActiveRecord
end
end
+ # Delete the given records from the association, using one of the methods :destroy,
+ # :delete_all or :nullify. The default method used is given by the :dependent option.
+ def delete_records(records, method = @reflection.options[:dependent])
+ raise NotImplementedError
+ end
+
def callback(method, record)
callbacks_for(method).each do |callback|
case callback