zoukankan      html  css  js  c++  java
  • update_all

    Base.update_all(updates, conditions = nil, options = {})

    前面为执行语句,后面为where语句。

    源码

    # File active_record/base.rb, line 670
    def update_all(updates, conditions = nil, options = {})
      sql  = "UPDATE #{table_name} SET #{sanitize_sql_for_assignment(updates)} "
      scope = scope(:find)
      add_conditions!(sql, conditions, scope)
      add_order!(sql, options[:order], scope)
      add_limit!(sql, options, scope)
      connection.update(sql, "#{name} Update")
    end
    

    例子

    # Update all billing objects with the 3 different attributes given
    Billing.update_all( "category = 'authorized', approved = 1, author = 'David'" )
    
    # Update records that match our conditions
    Billing.update_all( "author = 'David'", "title LIKE '%Rails%'" )
    
    # Update records that match our conditions but limit it to 5 ordered by date
    Billing.update_all( "author = 'David'", "title LIKE '%Rails%'",
                          :order => 'created_at', :limit => 5 )
    
  • 相关阅读:
    OpenStack概述、虚拟机部署OpenStack
    foo bar 的典故
    PWA
    react 虚拟dom心得
    背包问题总结
    leetcode 44 通配符匹配(dp)
    黑客与画家
    njuoj 递归查询字符串
    我的第一篇博客
    接口测试入门(二)
  • 原文地址:https://www.cnblogs.com/rubylouvre/p/1528827.html
Copyright © 2011-2022 走看看