的情況:accepts_nested_attributes_for與關鍵 「_destroy」
class Cellar < ActiveRecord::Base
belongs_to :house, dependent: :destroy
accepts_nested_attributes_for :house, allow_destroy: true
attr_accessible :house_id, :house_attributes, [...]
end
。
class House < ActiveRecord::Base
has_one: cellar
end
問題:
當我送Cellar
形式包括鍵值對"_destroy" => "true"
的house_attributes
內,衆議院被破壞,因爲它應該,但Cellar.house_id
未更新爲NULL。
這是正常的行爲嗎?我應該如何解決這個問題?
您的機型混雜聲明。你的'Cellar'模型在父'House'對象上被設置爲'dependent::destroy',但是你希望在房子被銷燬後保留'Cellar'對象嗎?這沒有任何意義的IMO。 – zeantsoi
即使我註釋掉'''dependent::destroy''',問題仍然保持不變。 – TomDogg
你的聯繫從根本上是有缺陷的。父母應該接受孩子的嵌套屬性 - 而不是相反。 – zeantsoi