0

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:

  1. call destroy method on profile.
  2. entries in degreeholderships table are marked active=NULL and have deleted_at=timestamp
  3. call restore method on profile and pass recursive: true
    • profile.restore(recursive: true)
  4. 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:

  1. Due to an error in my setup.
  2. Actually the expected behavior and if so please explain why this is preferred over being able to restore the dependents recursively.
  3. Is a bug with the gem.
sunya7a
  • 1
  • 1
  • 1

1 Answers1

0

Parameters: {"type"=>"restore", "id"=>"18"}

Pt Load (0.6ms) SELECT "pts".* FROM "pts" WHERE "pts"."deleted_at" IS NULL AND "pts"."id" = $1 LIMIT $2 [["id", 18], ["LIMIT", 1]]

overriding default queries works for all methods except destroy, really destroy, and restore

Completed 401 Unauthorized in 9ms (ActiveRecord: 1.3ms)

ActiveRecord::RecordNotFound (Couldn't find Product with 'id'=18 [WHERE "pts"."deleted_at" IS NULL]):

This is a simple 1 table with no associations ?

user1898553
  • 91
  • 1
  • 3
  • I had the same issue. In order to resolve it, I just used `acts_as_paranoid without_default_scope: true` in the corresponding model and used `.without_deleted` method, wherever I want to exclude the soft-deleted records. – Sree Raj Mar 27 '19 at 10:34