我有3张桌子
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时,我希望删除与之关联的所有accessories
。所以它不会返回任何错误。
然而它返回Accessory is marked as readonly
。所以我想知道我所做的事情是不是最优的,而是我应该做些什么。