下面的类
class Producttag < ApplicationRecord
belongs_to :product, optional: true
belongs_to :variant, optional: true
是其父的子级
class Product < ApplicationRecord
has_many :productags, dependent: :destroy
他们本身就在另外两个父母的链条中。每个类在其子类上调用dependent: :destroy
。
当对销毁操作运行测试时,每个类都会遇到相同的错误:
NameError: uninitialized constant Product::Productag
或在变体类上
NameError: uninitialized constant Variant::Productag
所有其他parnet子关系依赖项都会被销毁,但不会销毁后一个。唯一明显的区别是放在关系上的optional: true
。这是关于销毁行动中的错误的假设,但很难理解。
如果这就是动机,为什么?或者缺少什么,然后允许销毁"可选"子项记录?
类是Producttag
,但您的关系是has_many :productags, dependent: :destroy
。
你错过了一个";t〃;在产品tag中,这导致轨道寻找";class_name"Productag
也就是说ProductTag
和product_tag
会使更加明显