1

我有一个父模型,它有多个孩子,还有一个虚拟属性:

attr_accessor :new_assocation_model
has_many :children, -> { order("position ASC") }, autosave: true, inverse_of: :parent
accepts_nested_attributes_for :children, allow_destroy: true

这是子模型:

belongs_to :parent, inverse_of: :children
acts_as_list scope: :parent

当通过父级中的 update_attributes 销毁子级时,我们会丢失分配给父级虚拟属性的数据。如果我注释掉acts_as_list scope: :parent,分配给我的虚拟属性的数据将被保留。

有没有办法我们可以保留分配给虚拟属性的数据?

4

0 回答 0