Permalink
Browse files

Merge pull request #9668 from neerajdotname/9567-delete-all-warning

Show warning message if delete_all is firing callbacks
  • Loading branch information...
2 parents 816e7d1 + d71eaf3 commit 67b486142bd3ec42d4b1bffd5705aabd6a0cb4e0 @fxn fxn committed Mar 11, 2013
Showing with 9 additions and 0 deletions.
  1. +9 −0 activerecord/lib/active_record/associations/collection_association.rb
View
9 activerecord/lib/active_record/associations/collection_association.rb
@@ -204,6 +204,15 @@ def delete(*records)
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

0 comments on commit 67b4861

Please sign in to comment.