Setup
class Profile < ApplicationRecord
acts_as_paranoid
has_many :degreeholderships
has_many :degrees, through: :degreeholderships, dependent: :destroy
end
class Degreeholdership < ApplicationRecord
acts_as_paranoid column: :active, sentinel_value: true
belongs_to :profile
belongs_to :degree
validates :profile_id, presence: true
validates :degree_id, presence: true
def paranoia_restore_attributes
{
deleted_at: nil,
active: true
}
end
def paranoia_destroy_attributes
{
deleted_at: current_time_from_proper_timezone,
active: nil
}
end
end
class Degree < ApplicationRecord
has_many :degreeholderships
has_many :profiles, through: :degreeholderships, dependent: :destroy
end
Steps to reproduce:
- call destroy method on profile.
- entries in degreeholderships table are marked active=NULL and have deleted_at=timestamp
- call restore method on profile and pass recursive: true
- profile.restore(recursive: true)
- entries in degreeholderships table stay the same
Expected outcome:
- entries in degreeholderships that were associated with profile should be restored as well.
I have attempted to run restore with and without the recursive: true option as well as set the recovery_window value. All display this behavior. I have also removed the option to use the active column and revert back to using deleted_at (the default).
I'm looking to understand whether this behavior is:
- Due to an error in my setup.
- Actually the expected behavior and if so please explain why this is preferred over being able to restore the dependents recursively.
- Is a bug with the gem.