Ruby on rails 无法删除只读关联
我有三张桌子Ruby on rails 无法删除只读关联,ruby-on-rails,Ruby On Rails,我有三张桌子 class Product < ApplicationRecord has_many :accessories has_many :product_attribute_categories, through: :accessories, dependent: :destroy end class Accessory < ApplicationRecord belongs_to :product belongs_to :product_attrib
class Product < ApplicationRecord
has_many :accessories
has_many :product_attribute_categories, through: :accessories, dependent: :destroy
end
class Accessory < ApplicationRecord
belongs_to :product
belongs_to :product_attribute_category
end
class ProductAttributeCategory < ApplicationRecord
has_many :accessories, dependent: :destroy
has_many :products, through: :accessories
has_many :product_attributes, dependent: :destroy
类产品 拥有多个:产品属性类别,通过::附件,依赖::销毁
结束
类别附件<应用记录
属于:产品
属于:产品属性类别
结束
类ProductAttributeCategory
现在,当我尝试删除ProductAttributeCategory时,我希望删除与之关联的所有附件。所以它不会返回任何错误
但是它返回
附件标记为只读。因此,我想知道我所做的是否不是最优的,我应该做什么。在产品模型中有许多:产品属性类别,通过::附件,依赖::销毁看起来可疑。Rails通常破坏关联的“链接”表,而不是关联本身。在这种情况下,dependent::destroy应该位于has_many:accessories.has_many:product_属性_类别上,通过::accessories,产品模型中的dependent::destroy看起来可疑。Rails通常破坏关联的“链接”表,而不是关联本身。在这种情况下,dependent::destroy应该位于has_many:附件上。