ActsAsParanoid / acts_as_paranoid

ActiveRecord plugin allowing you to hide and restore records without actually deleting them.
MIT License
1.47k stars 192 forks source link

Order of before_destroy and acts_as_paranoid should not really matter #168

Open thebravoman opened 4 years ago

thebravoman commented 4 years ago

Given

class Episode < ApplicationRecord
   acts_as_paranoid
   before_destroy do 
      puts self.authors.count
   end
   has_many :authors, dependent: :destroy

and

class Episode < ApplicationRecord
   before_destroy do 
      puts self.authors.count
   end
   acts_as_paranoid 
   has_many :authors, dependent: :destroy

This for me outputs different size of authors. In the first case authors are already destroyed. Because of this I can not do anything with them in the before_destroy.

In the second case the authors are there.

Looking at the code like this I think it should not matter which comes first.

mvz commented 4 years ago

Hi @thebravoman, I dug into this a bit and indeed, it is surprising that this happens, even when looking at ActsAsParanoid's code.