摘要: 之前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力哥 阅读全文
posted @ 2013-11-25 18:53 wangyuyu 阅读(518) 评论(2) 推荐(0) 编辑