【发布时间】:2018-07-15 04:05:25
【问题描述】:
我在 Rails 5 上。
我有一个这样的多态关联:
models/enjoy_level.rb:
class EnjoyLevel < ApplicationRecord
belongs_to :enjoyable, polymorphic: true, touch: true, optional: true
end
models/mother.rb:
class Mother < ApplicationRecord
has_one :enjoy_level, as: :enjoyable, dependent: :destroy
accepts_nested_attributes_for :enjoy_level
end
如果我销毁一个mother(有touch: true 选项)它仍然:
- 销毁之前的
enjoy_level; - 将
Motherupdate_at设置为now(); - 最后销毁这个
Mother记录一。
第一步和第二步都没用,对吧?
我哪里错了?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-5 rails-activerecord