Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 无法删除只读关联_Ruby On Rails - Fatal编程技术网

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:附件上。