aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2013-03-11 15:17:08 -0400
committerNeeraj Singh <neerajdotname@gmail.com>2013-03-11 16:32:17 -0400
commitd71eaf3e3fb9e9a27a40805b0b724667f3b7a16a (patch)
tree2cd260152189976800272abd992e489b815ec6f4 /activerecord/lib/active_record
parent464cd9dc0648f1221ed2643d32c988d234ec5c49 (diff)
downloadrails-d71eaf3e3fb9e9a27a40805b0b724667f3b7a16a.tar.gz
rails-d71eaf3e3fb9e9a27a40805b0b724667f3b7a16a.tar.bz2
rails-d71eaf3e3fb9e9a27a40805b0b724667f3b7a16a.zip
Show warning message if delete_all is firing callbacks
`post.comments.delete_all` will fire callbacks if :dependent option is :destroy . It will be fixed in Rails 4.1 . In the meantime display a warning . Look at #9567 for details .
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 5feb149946..c992f51dbb 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -204,6 +204,15 @@ module ActiveRecord
dependent = options[:dependent]
if records.first == :all
+
+ if dependent && dependent == :destroy
+ message = 'In Rails 4.1 delete_all on associations would not fire callbacks. ' \
+ 'It means if the :dependent option is :destroy then the associated ' \
+ 'records would be deleted without loading and invoking callbacks.'
+
+ ActiveRecord::Base.logger ? ActiveRecord::Base.logger.warn(message) : $stderr.puts(message)
+ end
+
if loaded? || dependent == :destroy
delete_or_destroy(load_target, dependent)
else