1

has_many の子と仮想属性を持つ親モデルがあります。

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