还原递归不会还原连接表中的条目

问题描述 投票:0回答:1

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. 在配置文件上调用destroy方法。
  2. 在degreesholderships表中的条目标记为active = NULL并且deleted_at = timestamp
  3. 在profile上调用restore方法并传递recursive:true profile.restore(recursive:true)
  4. 学位持有人表中的条目保持不变

Expected outcome:

  • 还应恢复与个人资料相关联的学位持有人的条目。

我尝试使用和不使用recursive:true选项运行还原以及设置recovery_window值。全部显示此行为。我还删除了使用活动列的选项并恢复使用deleted_at(默认值)。

我想知道这种行为是否是:

  1. 由于我的设置错误。
  2. 实际上预期的行为,如果是这样,请解释为什么这是优先的,因为能够递归地恢复家属。
  3. 是宝石的错误。
ruby-on-rails-5 has-many-through soft-delete acts-as-paranoid ruby-paranoia
1个回答
0
投票

参数:{“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]]

覆盖默认查询适用于除destroy,真正销毁和恢复之外的所有方法

在9ms完成401未授权(ActiveRecord:1.3ms)

ActiveRecord :: RecordNotFound(找不到'id'= 18 [WHERE“pts”。“deleted_at”IS NULL]的产品):

这是一个没有关联的简单1表?

© www.soinside.com 2019 - 2024. All rights reserved.