zoukankan      html  css  js  c++  java
  • ruby大神与菜鸟的代码区别

    之前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
      end
    end
     
    力哥的代码:
    Category.each do |c|
      c.brand_ids = Brand.where(category_ids: c.id).collect(&:id)
      c.save
    end
     
    大神菜鸟高下立判
  • 相关阅读:
    AE旋转
    AE2
    AE1
    面试
    TS 基础数据类型
    vue-cli结构介绍
    js异步加载的5种方式
    slot 插槽的使用
    使用组件的细节点
    Vue 条件渲染
  • 原文地址:https://www.cnblogs.com/wangyuyu/p/3442062.html
Copyright © 2011-2022 走看看