摘要:
之前Brand类 has_and_belongs_to_many :categories, index: true现在在Category类 增加has_and_belongs_to_many :brands, index: true实现brand.categories关联的数据 同步到 cagegory.brands我写的代码:Brand.each do |brand| if brand.categories brand.categories.each do |category| category.brands << brand category.save end endend力哥 阅读全文