依赖性破坏不适用于STI类

时间:2016-02-06 15:02:57

标签: ruby-on-rails ruby-on-rails-4 sti

在尝试使用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那样访问所有正确的参数。

1 个答案:

答案 0 :(得分:0)

我通过将嵌套属性代码和has_many移动到基类来实现它。

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

class B < A

end

我认为它与rails中的STI问题相同,因为你无法更新STI类对象的类型(有针对性的解决方法)。

相关问题