依赖销毁不适用于 STI class

Dependent destroy not working for STI class

我在 rails 4 中尝试使用 STI 类 的嵌套属性来销毁时遇到问题。 例如:

class A < ActiveRecord::Base
end

class B < A
  has_many :options
  accepts_nested_attributes_for :options, :allow_destroy => true
end

当我尝试删除未被删除的选项时,它具有 marked_for_destruction? 作为 true,但该选项未被删除。

我可以访问所有正确的参数,例如 :id, :name, :_destroy

我通过将嵌套属性代码和 has_many 移动到基础 class 使其工作。

class A < ActiveRecord::Base
  has_many :options
  accepts_nested_attributes_for :options, :allow_destroy => true
end

class B < A

end

我认为 rails 中 STI 的问题与您无法更新 STI class 对象的类型相同(有解决方法)。