First of all I would like to inform that [acts_as_paranoid gem] is not updated for rails 4.
So in our project we have used [paranoia gem] which is similar to acts_as_paranoid.
Few days ago we faced a issue like once I archived a object then the associated object also deleted because of dependent: :destroy and I was recovering archived object but all details with the associated objects were lost.
Example: We had model structure like this
class Person acts_as_paranoid has_one :assets, as: :attachable, dependent: :destroy has_many :members, dependent: :destroy has_many :companies, through: :members, dependent: :destroy end class Company acts_as_paranoid has_many :assets, as: :attachable, dependent: :destroy has_many :members, dependent: :destroy has_many :people, through: :members, dependent: :destroy end class Member #some required attributes for person and company belongs_to :company belongs_to :person end class Asset belongs_to :attachable, polymorphic: true end
So to fix this issue we removed dependent: :destroy for all association.
But one more scenario was arises here. Like when I archived a person then the associated member object not deleted, then I tried access a company that have member record for that archived person. Then of course it would break.
So in this scenario we are using acts_as_paranoid for Member model also and keep dependent: :destroy with association.
So If I archive a person/company then associated member also archived automatically and to recover, paranoia provides a method Person.restore(id, recursive: true), like recover in acts_as_paranoid. So it will recover all associated archived objects as well.
One more advantage of paranoia is if you want to restore multiple records then you can use
Person.restore([id1, id2, ..., idN])
Subscribe to Engineering At Kiprosh
Get the latest posts delivered right to your inbox