之前Brand类 has_and_belongs_to_many :categories, index: true
现在在Category类 增加
has_and_belongs_to_many :brands, index: true
实现brand.categories关联的数据 同步到 cagegory.brands
Category.each do |c|
c.brand_ids = Brand.where(category_ids: c.id).collect(&:id)
c.save
end
网友评论