【发布时间】:2018-01-29 14:16:19
【问题描述】:
我在 Rails 5 中有 3 个模型:
产品
class Product < ApplicationRecord
belongs_to :category
has_and_belongs_to_many :stores
end
商店
class Store < ApplicationRecord
has_many :admin_users
has_and_belongs_to_many :roles
has_and_belongs_to_many :products
end
产品商店
class ProductsStores < ApplicationRecord
self.primary_key = :store_id
end
当我尝试使用命令 ProductsStores.first.destroy 删除连接表 ProductsStores 的一条记录时,连接表中的所有记录都会被销毁。为什么?
谁能帮帮我?
提前谢谢你!
【问题讨论】:
标签: mysql ruby-on-rails ruby