From f319e4a9421d8815717fd6ca6191268fed9e536d Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 13 May 2013 17:10:23 -0400 Subject: Do not invoke callbacks when delete_all is called Method `delete_all` should not be invoking callbacks and this feature was deprecated in Rails 4.0. This is being removed. `delete_all` will continue to honor the `:dependent` option. However if `:dependent` value is `:destroy` then the default deletion strategy for that collection will be applied. User can also force a deletion strategy by passing parameter to `delete_all`. For example you can do `@post.comments.delete_all(:nullify)` --- activerecord/test/models/bulb.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/test/models/bulb.rb') diff --git a/activerecord/test/models/bulb.rb b/activerecord/test/models/bulb.rb index 0109ef4f83..4361188e21 100644 --- a/activerecord/test/models/bulb.rb +++ b/activerecord/test/models/bulb.rb @@ -37,3 +37,9 @@ class CustomBulb < Bulb self.frickinawesome = true if name == 'Dude' end end + +class FunkyBulb < Bulb + before_destroy do + raise "before_destroy was called" + end +end -- cgit v1.2.3 From 5aab0c053832ded70a3a4b58cb97f8f8bba796ba Mon Sep 17 00:00:00 2001 From: Brian Thomas Storti Date: Sat, 23 Nov 2013 09:24:52 -0200 Subject: Raise `RecordNotDestroyed` when children can't be replaced Fixes #12812 Raise `ActiveRecord::RecordNotDestroyed` when a child marked with `dependent: destroy` can't be destroyed. The following code: ```ruby class Post < ActiveRecord::Base has_many :comments, dependent: :destroy end class Comment < ActiveRecord::Base before_destroy do return false end end post = Post.create!(comments: [Comment.create!]) post.comments = [Comment.create!] ```` would result in a `post` with two `comments`. With this commit, the same code would raise a `RecordNotDestroyed` exception, keeping the `post` with the same `comment`. --- activerecord/test/models/bulb.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/test/models/bulb.rb') diff --git a/activerecord/test/models/bulb.rb b/activerecord/test/models/bulb.rb index 4361188e21..831a0d5387 100644 --- a/activerecord/test/models/bulb.rb +++ b/activerecord/test/models/bulb.rb @@ -43,3 +43,9 @@ class FunkyBulb < Bulb raise "before_destroy was called" end end + +class FailedBulb < Bulb + before_destroy do + false + end +end -- cgit v1.2.3